Jooq "generateJooq" 导致 java.lang.ClassNotFoundException:jakarta.xml.bind.annotation.XmlSchema 在 Spring 引导应用程序中
Jooq "generateJooq" causing java.lang.ClassNotFoundException: jakarta.xml.bind.annotation.XmlSchema in Spring Boot App
我正在使用 Gradle 7.3.3 构建一个 Spring 引导应用程序,它使用 jooq 从预编译文件生成 Table、POJO 和记录 类现有的数据库架构。尝试将 jooqVersion 从 3.15.5 升级到 3.16.0 时,:generateJooq returns 出现以下错误:
> Task :generateJooq FAILED
1 actionable task: 1 executed
Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/xml/bind/annotation/XmlSchema
at org.jooq.util.jaxb.tools.MiniJAXB.getNamespace(MiniJAXB.java:400)
at org.jooq.util.jaxb.tools.MiniJAXB.addDefaultNamespace(MiniJAXB.java:188)
at org.jooq.util.jaxb.tools.MiniJAXB.unmarshal0(MiniJAXB.java:175)
at org.jooq.util.jaxb.tools.MiniJAXB.unmarshal(MiniJAXB.java:161)
at org.jooq.codegen.GenerationTool.load(GenerationTool.java:1180)
at org.jooq.codegen.GenerationTool.main(GenerationTool.java:203)
Caused by: java.lang.ClassNotFoundException: jakarta.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 6 more
Caused by: java.lang.ClassNotFoundException: jakarta.xml.bind.annotation.XmlSchema
:generateJooq 在 3.15.5 中运行良好。我们需要 3.16.0,因为它(据说)允许 DSL 操作 PostGIS 查询。
许多帖子都推荐了这个,但在这种情况下没有用。
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.1'
我目前正在使用 Azul Zulu 版本 15.0.5 (JDK 15),以及 Gradle:
的 Jooq 插件
import nu.studer.gradle.jooq.JooqEdition
plugins {
id 'java'
id 'jacoco'
id 'maven-publish'
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'com.github.johnrengelman.shadow' version '5.2.0'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'com.jfrog.artifactory' version '4.16.0'
id 'nu.studer.jooq' version '6.0.1'
}
我的依赖如下:
ext {
assertjVersion = '3.22.0'
awsSdkVersion = '1.11.812'
awsLambdaEventsVersion = '2.2.9' //version 3.1.0 does not deserialize S3Event properly
awsLambdaCoreVersion = '1.2.1'
geojsonJacksonVersion = '1.14'
lombokVersion = '1.18.22'
mapstructVersion = '1.4.2.Final'
postgresVersion = '42.3.1'
slf4jVersion = '1.7.32'
springCloudFunctionVersion = '3.0.6.RELEASE'
springCloudVersion = '2.2.6.RELEASE'
testNGVersion = '7.4.0'
msDbSchemaVersion = '0.10.10'
jooqVersion = '3.16.0'
}
dependencies {
implementation("org.mapstruct:mapstruct:${mapstructVersion}")
annotationProcessor("org.mapstruct:mapstruct-processor:${mapstructVersion}")
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
compileOnly("org.projectlombok:lombok:${lombokVersion}")
implementation("org.springframework.cloud:spring-cloud-function-context")
implementation("org.springframework.cloud:spring-cloud-starter-function-web")
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
implementation("de.grundid.opendatalab:geojson-jackson:${geojsonJacksonVersion}")
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.1'
implementation 'org.liquibase:liquibase-core'
implementation("org.jooq:jooq:${jooqVersion}")
jooqGenerator("org.postgresql:postgresql:${postgresVersion}")
implementation('org.springframework.boot:spring-boot-starter-jooq')
implementation("org.postgresql:postgresql:${postgresVersion}")
implementation("com.amazonaws:aws-lambda-java-events:${awsLambdaEventsVersion}")
implementation("com.amazonaws:aws-lambda-java-core:${awsLambdaCoreVersion}")
implementation("com.amazonaws:aws-java-sdk-s3:${awsSdkVersion}")
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation("org.testng:testng:${testNGVersion}")
testImplementation("org.assertj:assertj-core:${assertjVersion}")
}
更新:使用依赖性洞察显示 jakarta.xml.bind:jakarta.xml.bind-api
被强制降到 2.3.3,但没有任何东西(据我所知)提供执行此操作的规则。
$ ./gradlew --scan -q dependencyInsight --configuration jooqGenerator --dependency jakarta.xml.bind-api
jakarta.xml.bind:jakarta.xml.bind-api:2.3.3 (selected by rule)
variant "runtime" [
org.gradle.status = release (not requested)
org.gradle.usage = java-runtime (not requested)
org.gradle.libraryelements = jar (not requested)
org.gradle.category = library (not requested)
]
jakarta.xml.bind:jakarta.xml.bind-api:3.0.0 -> 2.3.3
\--- org.jooq:jooq:3.16.3
+--- org.jooq:jooq-codegen:3.16.3
| \--- jooqGenerator (requested org.jooq:jooq-codegen)
\--- org.jooq:jooq-meta:3.16.3
\--- org.jooq:jooq-codegen:3.16.3 (*)
(*) - dependencies omitted (listed previously)
用于 jOOQ 代码生成的第三方 gradle 插件尚未准备好用于 jOOQ 3.16。此处正在讨论修复:https://github.com/etiennestuder/gradle-jooq-plugin/pull/208
将 io.spring.dependency-management
放入构建隔离解决了使用 nu.studer.jooq
插件 7.0 版时的问题:
plugins {
id 'java'
id 'jacoco'
id 'maven-publish'
id 'org.springframework.boot' version '2.6.3'
id 'com.github.johnrengelman.shadow' version '5.2.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE' apply false
id 'com.jfrog.artifactory' version '4.16.0'
id 'nu.studer.jooq' version '7.0'
}
然后:
build {
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
}
}
}
这是因为 io.spring.dependency-management
强制(根据规则)jakarta.xml.bind:jakarta.xml.bind-api
版本从 3.0.0 降到 2.3.3。
最近的 v7.0 of the gradle-jooq-plugin 解决了这个问题并与 3.16.x 兼容。仍在使用 jOOQ <=3.15 的人应该继续使用 v6.0.1。
我正在使用 Gradle 7.3.3 构建一个 Spring 引导应用程序,它使用 jooq 从预编译文件生成 Table、POJO 和记录 类现有的数据库架构。尝试将 jooqVersion 从 3.15.5 升级到 3.16.0 时,:generateJooq returns 出现以下错误:
> Task :generateJooq FAILED
1 actionable task: 1 executed
Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/xml/bind/annotation/XmlSchema
at org.jooq.util.jaxb.tools.MiniJAXB.getNamespace(MiniJAXB.java:400)
at org.jooq.util.jaxb.tools.MiniJAXB.addDefaultNamespace(MiniJAXB.java:188)
at org.jooq.util.jaxb.tools.MiniJAXB.unmarshal0(MiniJAXB.java:175)
at org.jooq.util.jaxb.tools.MiniJAXB.unmarshal(MiniJAXB.java:161)
at org.jooq.codegen.GenerationTool.load(GenerationTool.java:1180)
at org.jooq.codegen.GenerationTool.main(GenerationTool.java:203)
Caused by: java.lang.ClassNotFoundException: jakarta.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 6 more
Caused by: java.lang.ClassNotFoundException: jakarta.xml.bind.annotation.XmlSchema
:generateJooq 在 3.15.5 中运行良好。我们需要 3.16.0,因为它(据说)允许 DSL 操作 PostGIS 查询。
许多帖子都推荐了这个,但在这种情况下没有用。
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.1'
我目前正在使用 Azul Zulu 版本 15.0.5 (JDK 15),以及 Gradle:
的 Jooq 插件import nu.studer.gradle.jooq.JooqEdition
plugins {
id 'java'
id 'jacoco'
id 'maven-publish'
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'com.github.johnrengelman.shadow' version '5.2.0'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'com.jfrog.artifactory' version '4.16.0'
id 'nu.studer.jooq' version '6.0.1'
}
我的依赖如下:
ext {
assertjVersion = '3.22.0'
awsSdkVersion = '1.11.812'
awsLambdaEventsVersion = '2.2.9' //version 3.1.0 does not deserialize S3Event properly
awsLambdaCoreVersion = '1.2.1'
geojsonJacksonVersion = '1.14'
lombokVersion = '1.18.22'
mapstructVersion = '1.4.2.Final'
postgresVersion = '42.3.1'
slf4jVersion = '1.7.32'
springCloudFunctionVersion = '3.0.6.RELEASE'
springCloudVersion = '2.2.6.RELEASE'
testNGVersion = '7.4.0'
msDbSchemaVersion = '0.10.10'
jooqVersion = '3.16.0'
}
dependencies {
implementation("org.mapstruct:mapstruct:${mapstructVersion}")
annotationProcessor("org.mapstruct:mapstruct-processor:${mapstructVersion}")
annotationProcessor("org.projectlombok:lombok:${lombokVersion}")
compileOnly("org.projectlombok:lombok:${lombokVersion}")
implementation("org.springframework.cloud:spring-cloud-function-context")
implementation("org.springframework.cloud:spring-cloud-starter-function-web")
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
implementation("de.grundid.opendatalab:geojson-jackson:${geojsonJacksonVersion}")
implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.1'
implementation 'org.liquibase:liquibase-core'
implementation("org.jooq:jooq:${jooqVersion}")
jooqGenerator("org.postgresql:postgresql:${postgresVersion}")
implementation('org.springframework.boot:spring-boot-starter-jooq')
implementation("org.postgresql:postgresql:${postgresVersion}")
implementation("com.amazonaws:aws-lambda-java-events:${awsLambdaEventsVersion}")
implementation("com.amazonaws:aws-lambda-java-core:${awsLambdaCoreVersion}")
implementation("com.amazonaws:aws-java-sdk-s3:${awsSdkVersion}")
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation("org.testng:testng:${testNGVersion}")
testImplementation("org.assertj:assertj-core:${assertjVersion}")
}
更新:使用依赖性洞察显示 jakarta.xml.bind:jakarta.xml.bind-api
被强制降到 2.3.3,但没有任何东西(据我所知)提供执行此操作的规则。
$ ./gradlew --scan -q dependencyInsight --configuration jooqGenerator --dependency jakarta.xml.bind-api
jakarta.xml.bind:jakarta.xml.bind-api:2.3.3 (selected by rule)
variant "runtime" [
org.gradle.status = release (not requested)
org.gradle.usage = java-runtime (not requested)
org.gradle.libraryelements = jar (not requested)
org.gradle.category = library (not requested)
]
jakarta.xml.bind:jakarta.xml.bind-api:3.0.0 -> 2.3.3
\--- org.jooq:jooq:3.16.3
+--- org.jooq:jooq-codegen:3.16.3
| \--- jooqGenerator (requested org.jooq:jooq-codegen)
\--- org.jooq:jooq-meta:3.16.3
\--- org.jooq:jooq-codegen:3.16.3 (*)
(*) - dependencies omitted (listed previously)
用于 jOOQ 代码生成的第三方 gradle 插件尚未准备好用于 jOOQ 3.16。此处正在讨论修复:https://github.com/etiennestuder/gradle-jooq-plugin/pull/208
将 io.spring.dependency-management
放入构建隔离解决了使用 nu.studer.jooq
插件 7.0 版时的问题:
plugins {
id 'java'
id 'jacoco'
id 'maven-publish'
id 'org.springframework.boot' version '2.6.3'
id 'com.github.johnrengelman.shadow' version '5.2.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE' apply false
id 'com.jfrog.artifactory' version '4.16.0'
id 'nu.studer.jooq' version '7.0'
}
然后:
build {
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
}
}
}
这是因为 io.spring.dependency-management
强制(根据规则)jakarta.xml.bind:jakarta.xml.bind-api
版本从 3.0.0 降到 2.3.3。
最近的 v7.0 of the gradle-jooq-plugin 解决了这个问题并与 3.16.x 兼容。仍在使用 jOOQ <=3.15 的人应该继续使用 v6.0.1。