问题描述
我正在从 openjdk 8 迁移到 openjdk 11。
使用 java8 gradle 配置,Jaxb 源代码生成在 java 11 中失败。
我为 java 11 添加了依赖 javax.xml.bind:jaxb-api:2.3.1,然后代码生成问题解决了。但我在此期间遇到错误 gradlew 干净构建
Errors occurred while build effective model from C:\Users\smith\.gradle\caches\modules-2\files-2.1\com.sun.xml.bind\jaxb-osgi\2.2.11\3cfdbd97851da417f2649a257d4087798b05b066\jaxb-osgi-2.2.11.pom:
'dependencyManagement.dependencies.dependency.systemPath' for com.sun:tools:jar must specify an absolute path but is ${tools.jar} in com.sun.xml.bind:jaxb-osgi:2.2.11
下面是gradle配置。
configurations {
jaxb
tfSchemas { transitive = false }
}
dependencies {
tfSchemas "com.tomotis.food.order.jaxb.schemas:food-order-schemas:${foodorderSchemasversion}"
jaxb 'com.sun.xml.bind:jaxb-osgi:2.2.11'
jaxb "javax.xml.bind:jaxb-api:2.3.1"
jaxb 'org.jvnet.jaxb2_commons:jaxb2-basics:0.6.3'
jaxb "org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.6.5"
jaxb "org.jvnet.jaxb2_commons:jaxb2-basics-annotate:1.0.2"
jaxb "com.fasterxml.jackson.core:jackson-databind:2.9.6"
implementation('javax.xml.bind:jaxb-api:2.3.1')
}
task generateSources() {
doLast {
def jaxbTargetDir = file("$buildDir/src")
copy{
from(zipTree(configurations.tfSchemas.singleFile).matching {
include "schemas/ok/*.xsd"
include "schemas/gn/genqr.xsd"
include "schemas/gn/genmwr.xsd"
include "schemas/common.xsd"
})
into("$buildDir/resources/jaxb")
eachFile { f ->
f.path = f.path.replaceFirst("schemas/ok/",'xsd/')
f.path = f.path.replaceFirst("schemas/gn/",'xsd/')
f.path = f.path.replaceFirst("schemas",'')
}
includeEmptyDirs false
}
filetree xsdFilesTree = filetree(dir: "$buildDir/resources/jaxb/xsd")
xsdFilesTree.include '*.xsd'
filetree commonXsdFilesTree = filetree(dir: "$buildDir/resources/jaxb")
commonXsdFilesTree.include '*.xsd'
xsdFilesTree = xsdFilesTree.plus(commonXsdFilesTree)
ant.taskdef(name: 'xjc',classname: 'org.jvnet.jaxb2_commons.xjc.XJC2Task',classpath: configurations.jaxb.asPath)
xsdFilesTree.getFiles().each {
File xsdFile ->
def xsdFileName = xsdFile.name.replace("-","_")
def xsdPackageExt = xsdFileName.take(xsdFileName.lastIndexOf("."))
String xsdFilePath = xsdFile.getAbsolutePath();
def bindings
def schema
if(xsdPackageExt =="common"){
bindings = "${projectDir}/src/main/resources/jaxb/binding.xjb"
schema = "$buildDir/resources/jaxb/common.xsd"
}else{
copy {
from "${projectDir}/src/main/resources/jaxb"
into "$buildDir/resources/jaxb"
rename {String fileName -> fileName.replace("common.xjb","${xsdPackageExt}.xjb")}
filter(org.apache.tools.ant.filters.Replacetokens,tokens: [SCHEMALOCATION: xsdPackageExt])
}
bindings = "$buildDir/resources/jaxb/${xsdPackageExt}.xjb"
schema = "$buildDir/resources/jaxb/xsd/${xsdPackageExt}.xsd"
}
ant.xjc(
destdir: "${jaxbTargetDir}",package:"com.tomotis.tax.order.ok.report.jaxb.$xsdPackageExt",schema: "$schema",binding:"$bindings",removeOldOutput: 'yes',extension: 'true'
)
{
arg(line: '-nv -disableXmlSecurity')
arg(value: "-Xannotate")
arg(line: "-Xinheritance")
}
file("$buildDir/src/com/tomotis/food/order/ok/report/jaxb/$xsdPackageExt/ObjectFactory.java").delete()
file("$buildDir/src/com/tomotis/food/order/ok/report/jaxb/$xsdPackageExt/package-info.java").delete()
}
}
}
compileJava {
dependsOn generateSources
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)