@Vampire are you out there???
Gradle gurus, I am STUCK. Looking to use org.glassfish.jaxb to convert XSD to Java. I have searched the internet over and came across a great Youtube video https://www.youtube.com/watch?v=tsRDNPWITZA (Thank Luke Chaffeey) then StackOverflow - How to run jaxb xjc task with gradle? - Stack Overflow (Which seems to use the YouTube approach)
While running
./gradlew generateSources
I get the following:
Could not find method compile() for arguments [generated classes] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
// BEGIN jaxb convert XSD to Java Classes
sourceSets {
generated {
// java.srcDir "$generated_dir" // >> is this supposed to be in the gradle.properties asking for
// knowledge
java.srcDir("${projectDir}/src/main/java")
}
}
// JAXB configuration holds classpath for running the JAXB XJC compiler
configurations {
jaxb
}
dependencies {
jaxb "org.glassfish.jaxb:jaxb-xjc:2.4.0-b180830.0438"
jaxb "org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438"
implementation "org.glassfish.jaxb:jaxb-xjc:2.4.0-b180830.0438"
implementation "org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438"
}
dependencies {
compile sourceSets.generated.output
// Generated code depends on the JAXB API, which is removed from base Java in JDK 11
compile "org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438"
generatedComplile "org.glassfish.jaxb:jaxb-runtime:2.4.0-b180830.0438"
}
// XJC tasks
// Cookie cutter function for defining multiple XJC tasks
// (not necessary if you only have a single task)!
def addXjcTask(taskName, schema, pkg, dest) {
// If you haven't already, create the generated output dir before running XJC or it will fail
file(dest).mkdirs()
// The main XJC task, calls XJCFacade which is the entry point of the XJC JAR
tasks.create(name: taskName, type: JavaExec) {
classpath configurations.jaxb
mainClass 'com.sun.tool.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 "-no-header"
}
// Add a dependency on the new task so it gets invoked
// >> Comment out to see if this works // compileGeneratedJava.dependsOn tasks.getByName(taskName)
}
// Add all the XJC tasks you need
addXjcTask("UniversalObjectLCC202210v05.02.00.xsd",
"${projectDir}/src/main/resources/xsd/iso/SomeXSDFile.xsd",
"com.company.iso.v05200",
"$generated_dir")
tasks.register("generateSources"){
description "Generate Java sources from XSD files"
dependsOn tasks.getByName("UniversalObjectLCC202210v05.02.00.xsd")
}
// END jaxb convert XSD to Java Classes