For quite a while I’ve been looking at converting a Maven build of a CXF JAX-RS application to use Gradle.
The gnarly part is using XJC (with JAXB extensions) to generate Java classes.
I’ve followed some advice to use the Ant XJCTask. This comes close, but it doesn’t work with JAXB extensions. It generates code if I don’t reference the extensions, but once I add them I get an error like the following:
java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider dk.conspicio.jaxb.plugins.XmlElementWrapperPlugin not a subtype
I get this error for both of the two JAXB extensions I’m using (I have to remove the reference to this one to see the similar error for the second one).
I’ve posted about this in various places, and the closest I’ve come is a note from Martin Gainty explaining how the ServiceLoader works. Unfortunately, that doesn’t really help me see a solution.
Note that I tried the recently added JAXB Gradle plugin. Unfortunately, at this time that plugin is too restrictive, not allowing me to specify individual XSD files (it just takes a directory name, and it processes all XSDs in the folder). I’ve proposed an extension to the author, and I’ve looked at the code to see what might be required to do this, but in the meantime I’m attempting to get this working with just the Ant task.
The following is the task I’ve defined, along with the dependencies I added for this.
task processXSDs() << {
ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask',
classpath: configurations.jaxb.asPath)
ant.xjc(destdir: 'tmp', package: "com.att.sunlight.service.domain.serviceCallResults", extension: true) {
schema(dir: "src/main/resources/schema", includes: "serviceCallResults.xsd")
arg(value: "-Xxew")
arg(value: "-summary target/xew-summary.txt")
arg(value: "-instantiate lazy")
arg(value: "-Xfluent-api")
}
}
jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.6'
jaxb 'com.sun.xml.bind:jaxb-impl:2.2.6'
jaxb 'javax.xml.bind:jaxb-api:2.2.6'
jaxb "JAXBXMLElementWrapperPlugin:JAXBXMLElementWrapperPlugin:1.0.0"
jaxb "net.java.dev.jaxb2-commons:jaxb-fluent-api:2.1.8"
I had one suggestion to add a classpath setting to the xjc element also. That makes no difference. I had originally set the “line” property of the “arg” elements instead of the “value” property, but neither makes any difference to the problem.
Any ideas?