I have an application that uses Java-classes that are generated with gradle from xsd-file implemented using JDK 8.
Now we must migrate to JAVA17.
The class-generation no longer works.
A xjc plugin 'org.unbroken-dome.xjc' version '2.0.0'
has been used for this, but this generate javax.xml... instead of jakarta.xml...
Giving error: package javax.xml.bind.annotation does not exist
What should I do to fix this?
The gradle.build file:
plugins {
id 'java-library'
id 'org.unbroken-dome.xjc' version '2.0.0'
}
dependencies {
implementation ....
}
xjc {
srcDirName = 'resources/xsd'
extension = true
}
I have added to build.gradle
implementation ('jakarta.xml.bind:jakarta.xml.bind-api:4.0.0')
I have found information that the xjb-bindingfile must be updated from
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:version="2.1">
To
<jaxb:bindings xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="https://jakarta.ee/xml/ns/jaxb/xjc"
jaxb:version="3.0">
But when I do that I get ERROR, complaining about the url's beeing wrong
> A failure occurred while executing org.unbrokendome.gradle.plugins.xjc.work.xjc23.XjcGeneratorWorkAction
> Parse failed
Have also searched for days for other plugins to use but I cant get them to work, maybe my gradle knowlegde is too poor...
Looking at the source code of this gradle plugin your are using: 'org.unbroken-dome.xjc' version '2.0.0'
, seems possible to use jakarta api instead of java.xml.bind (which was removed since Java 11) configuring the xjcVersion
property, and using jakarta.xml.bind:jakarta.xml.bind-api:3.0.0-RC3
dependency instead of jakarta 4.0.0 (because seems that it's not already suported).
xjc {
xjcVersion = '3.0'
}
dependencies {
// XJC 3.0 requires a different JAXB API artifact
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.0-RC3'
}
You can see a sample in the plugin source repository: https://github.com/unbroken-dome/gradle-xjc-plugin/blob/master/samples/groovy-dsl/xjc-version-3_0/build.gradle
As additional comment, note that the last version of this plugin is from 2020 and seems that it's not currently in development, if you want to support new jakarta versions maybe you can try with other plugins which are in development and support newer versions for this library: https://github.com/bjornvester/xjc-gradle-plugin