Раньше это работало с предыдущей версией Spring-boot v2.x с зависимостями org.jvnet.jaxb2_commons, но после обновления до Spring-boot v3.x и перехода в пространство имен jakarta
компилятор xjc выдает эту ошибку< /p>
Execution failed for task ':test-schema:generateTypes'.
> java.lang.AssertionError: jakarta.xml.bind.JAXBException
- with linked exception:
[org.glassfish.jaxb.runtime.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
org.glassfish.jaxb.core.api.impl.NameConverter is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at org.glassfish.jaxb.core.api.impl.NameConverter
at public org.glassfish.jaxb.core.api.impl.NameConverter com.sun.tools.xjc.reader.xmlschema.bindinfo.BIGlobalBinding.nameConverter
at com.sun.tools.xjc.reader.xmlschema.bindinfo.BIGlobalBinding
]
Это мой файл build.gradle для запуска задачи компиляции xjc «generateTypes»
configurations {
xsd
xjc
}
ext {
xsdDir = "${sourceSets.main.output.resourcesDir}/xsd"
pojoSourceXsd = '**/*efs*.xsd'
generatedSrcDir = "${projectDir}/src/generated/java"
}
if (project.hasProperty('libraryVersion')) {
project.version = project.getProperty('libraryVersion')
}
sourceSets {
main {
java {
srcDir 'src/main/java'
srcDir 'src/generated/java'
}
resources {
srcDir 'src/main/resources'
srcDir 'src/generated/resources'
}
}
}
apply plugin: "io.spring.dependency-management"
dependencyManagement {
resolutionStrategy {
cacheChangingModulesFor 0, 'seconds'
}
}
dependencies {
project.repositories.removeAll {
it instanceof MavenArtifactRepository && it.url.toString() == 'https://artylab.booking.cloud/public-maven-virtual'
}
xsd 'booking:com.booking.e3.data.financetypes.v4:4.9.11@xsd'
xsd 'booking:com.booking.e3.data.financetypes.v5:5.1.9@xsd'
xsd 'booking:com.booking.e3.data.basetypes.v4:4.4.5@xsd'
xsd 'booking:com.booking.e3.data.timetypes.v4:4.1.0@xsd'
xsd 'booking:com.booking.e3.data.placetypes.v4:4.1.3@xsd'
// XJC plugin to equals, hashCode and toString methods
//xjc 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:1.11.1'
//xjc 'org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1'
//xjc 'org.jvnet.jaxb2_commons:jaxb2-basics-annotate:1.0.3'
//xjc 'com.fillumina:krasa-jaxb-tools:2.3.5'
xjc ('org.jvnet.jaxb:jaxb-plugins:3.0.0') {
exclude (group: 'commons-beanutils')
exclude (group: 'commons-io')
}
xjc ('org.jvnet.jaxb:jaxb-plugin-annotate:3.0.0') {
exclude (group: 'commons-beanutils')
exclude (group: 'commons-io')
}
// XJC Runtime part to support plugins
// implementation 'org.jvnet.jaxb2_commons:jaxb2-basics-runtime:1.11.1'
// implementation 'jakarta.validation:jakarta.validation-api:3.0.2'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.0'
implementation 'org.glassfish.jaxb:jaxb-xjc:3.0.2'
implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.2'
testImplementation 'junit:junit:4.13.2'
configurations.all {
exclude group: 'javax.xml.bind', module: 'jaxb-api'
exclude group: 'com.sun.xml.bind', module: 'jaxb-impl'
exclude group: 'com.sun.xml.bind', module: 'jaxb-core'
}
components {
all { details ->
if (details.id.group == "booking") {
details.statusScheme = ["continuousintegration", "directedbuilds", "releasecandidate", "release"]
}
}
}
}
clean.delete generatedSrcDir
tasks.register('copyXsdDependencies', Copy) {
description 'Copies imported XSDs to the build directory.'
println configurations.xsd.files
from configurations.xsd
into "$xsdDir/temp"
include '**/*.xsd'
// Strip version from file name for external XSDs
rename ~/(.*)-.*(\.\w+)/, '$1$2'
// Fixup any import naming issues due to case sensitivity (e.g. FinanceTypes should be changed to finance types).
doLast {
new File(xsdDir).list([accept: { d, file -> file ==~ /.*?\.xsd/ }] as FilenameFilter).toList().each { file ->
def xsdFile = new File(xsdDir, file);
def text = xsdFile.text
text = (text =~ /BaseTypes/).replaceAll('basetypes')
text = (text =~ /PlaceTypes/).replaceAll('placetypes')
text = (text =~ /PersonTypes/).replaceAll('persontypes')
text = (text =~ /FinanceTypes/).replaceAll('financetypes')
text = (text =~ /MessageTypes/).replaceAll('messagetypes')
text = (text =~ /TimeTypes/).replaceAll('timetypes')
xsdFile.write(text)
}
}
}
processResources.dependsOn copyXsdDependencies
tasks.register('generateTypes') {
dependsOn processResources
description "Generates POJOs from the XSDs."
inputs.files project.files(xsdDir)
outputs.dir(generatedSrcDir)
doLast {
mkdir generatedSrcDir
ant {
// fix schemaLocations: ensure all XSD names are in lowercase
println 'replacing files...'
xslt(extension: ".xsd", style: "src/main/resources/xsd/convert.xsl", force: "true", includes: "*.xsd",
basedir: "$xsdDir/temp", destdir: xsdDir) {
outputproperty(name: "method", value: "xml")
outputproperty(name: "standalone", value: "yes")
outputproperty(name: "indent", value: "yes")
}
delete(dir: "$xsdDir/temp")
// create custom JAXB bindings for xjc
path(id: "xsds.path") { fileset(dir: "$xsdDir", includes: "*.xsd") }
property(name: "xsds", refid: "xsds.path")
xslt(in: "src/main/resources/xsd/bindings.xml",
out: "$xsdDir/jaxb-binding.xml",
style: "src/main/resources/xsd/bindings.xsl") {
param(name: "xsds", expression: "${xsds}")
}
// run xjc compiler
taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: sourceSets.main.runtimeClasspath.asPath)
xjc(extension: true, destdir: generatedSrcDir, binding: "$xsdDir/jaxb-binding.xml") {
schema(dir: xsdDir, includes: "*.xsd")
classpath(path: configurations.xjc.asPath)
arg(value: '-Xinheritance')
arg(value: '-Xannotate')
arg(value: '-XtoString')
arg(value: '-Xcopyable')
arg(value: '-Xfluent-api')
arg(value: "-nv")
arg(value: '-Xvalue-constructor')
}
}
}
}
compileJava.dependsOn generateTypes
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from sourceSets.main.allJava, copyXsdDependencies.outputs.files
// pack runtime dependencies in the same jar file, internally schema project is imported using *jar extension
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
def dists = [
[name: 'POE', artifactId: 'com.booking.efs.test.purchase.event.messages.v1'],
[name: 'PO', artifactId: 'com.booking.efs.test.purchaseorder.v1'],
[name: 'Common', artifactId: 'com.booking.efs.test.common.v1'],
[name: 'BE', artifactId: 'com.booking.efs.test.business.event.messages.v1'],
[name: 'Event', artifactId: 'com.booking.efs.test.event.v1'],
[name: 'Order', artifactId: 'com.booking.efs.test.order.v1'],
[name: 'Supply', artifactId: 'com.booking.efs.test.common.supplytypes.v1']
]
publishing {
publications {
dists.each { dist ->
//Every publication has name of the distibution
"xsd${dist.name}"(MavenPublication) {
groupId 'com.booking'
version project.version
artifactId = "${dist.artifactId}"
artifact("$xsdDir/${dist.artifactId}.xsd") {
extension "xsd"
}
}
}
//publishing task for test-schema project
maven(MavenPublication) {
groupId 'com.booking'
version project.version
artifact jar
}
}
repositories {
maven {
url System.getenv('PUBLISH_ARTIFACTORY_URL')
credentials {
if (project.hasProperty('ARTIFACTORY_USER')) {
username = "${project.'ARTIFACTORY_USER'}"
} else {
username = System.getenv("ARTIFACTORY_USER")?: "${ARTIFACTORY_USER}"
}
if (project.hasProperty('ARTIFACTORY_PASS')) {
password = "${project.'ARTIFACTORY_PASS'}"
} else if (project.hasProperty('ARTIFACTORY_PASSWORD')) {
password = "${project.'ARTIFACTORY_PASSWORD'}"
} else {
password = System.getenv("ARTIFACTORY_PASSWORD")?: "${ARTIFACTORY_PASS}"
}
}
}
}
}
task publishSnapshotXsd(dependsOn: [dists.collect { "publishXsd${it.name}ReleasePublicationToSnapshotRepository" }]) {
description 'Publishes XSD artifacts to the snapshot repostiory.'
}
task publishSnapshot() {
description 'Publishes artifacts to the snapshot repostiory.'
dependsOn publishSnapshotXsd
}
task publishReleaseXsd(dependsOn: [dists.collect { "publishXsd${it.name}ReleasePublicationToReleaseRepository" }]) {
description 'Publishes XSD artifacts to the snapshot repostiory.'
}
task publishRelease() {
dependsOn publishReleaseXsd
description 'Publishes artifacts to release.'
}
Это файл привязок.xsl
Подробнее здесь: https://stackoverflow.com/questions/791 ... -boot-v3-x
XJC не может генерировать классы с использованием привязок в Spring-boot v3.x ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
XJC не может генерировать классы с использованием привязок в Spring-boot v3.x
Anonymous » » в форуме JAVA - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-