0

I got a Quarkus microservice, and I'm using an XJC Gradle task for generating java classes out of XSD schemas like this: (It's based on the second answer of this post: How to generate jaxb classes from xsd using gradle, jaxb and xjc, classes should have XmlRootElement

// The folter to put the generated XJC Java classes in
def generatedXjcClassesDir = "src/generated/java"

sourceSets {
    generated {
        java.srcDir generatedXjcClassesDir
    }
}

dependencies {
    // Also compile the generated XJC Java classes
    compile sourceSets.generated.output

    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
    generatedCompile 'org.glassfish.jaxb:jaxb-runtime:2.3.3'
}

/**
 * XJC stuff
 *
 **/
configurations {
    // Having a separate configuration for XJC plugin only
    xjc
}

dependencies {
    xjc 'org.glassfish.jaxb:jaxb-xjc:2.3.3'
}

def xjcTask(taskName, schema, pkg, dest) {

    // Create (if not existing yet) the destination directory
    file(dest).mkdirs()

    // Calling XJCFacade which is the entry point of the XJC JAR
    tasks.create(name: taskName, type: JavaExec) {
        classpath configurations.xjc
        main 'com.sun.tools.xjc.XJCFacade'

        // To explore available args, download the XJC JAR manually and run java -jar jaxb-xjc.jar --help
        args schema, "-p", pkg, "-d", dest
    }
    // 
    compileGeneratedJava.dependsOn tasks.getByName(taskName)
}

xjcTask('xjcSchema1', 'src/main/xsd/SCL.xsd', 'org.lfenergy.compas', generatedXjcClassesDir)

It does work pretty well, all java classes are being generated and putted into the src/generated/java folder.

But the quarkus application doesn't compile correctly, because it gives the following error:

> Task :quarkusGenerateCode FAILED
Caching disabled for task ':quarkusGenerateCode' because:
  Build cache is disabled
Task ':quarkusGenerateCode' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
preparing quarkus application
:quarkusGenerateCode (Thread[Execution worker for ':',5,main]) completed. Took 1.487 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':quarkusGenerateCode'.
> Error while reading file as JAR: /Users/rob/Code/CoMPAS/compas-cim-mapping/build/resources/generated

I tried search for the error, but my Quarkus knowledge lacks here. Can somebody help me out? :)

Rob
  • 1
  • 1
  • can you run with gradle -s or -S to get the full stacktrace /details of error ? – Max Rydahl Andersen Mar 18 '21 at 19:22
  • Running with -s is of couse possible and I forgot to add it to the post, thanks! The final exception is: Caused by: java.nio.file.NoSuchFileException: /Users/rob/Code/CoMPAS/compas-cim-mapping/build/resources/generated. I'm just wondering why it searches over there. It seems like it's the final step, because compiling works and I can use the generated classes in my code. But the compilation just doesn't end succesfully. – Rob Mar 19 '21 at 08:14
  • Sounds like bug on first glance. Best you can do is make a reproducer and open issue on quarkusio – Max Rydahl Andersen Mar 19 '21 at 09:40

0 Answers0