尽管已将jaxb-api
定义为依赖项JAXBContext
,但在执行任务genJaxb
时找不到。添加jaxb-core
和jaxb-impl
无效。
错误消息:
FAILURE: Build failed with an exception. * Where: Build file '/Users/user/IdeaProjects/idx/fmd/build.gradle' line: 19 * What went wrong: Execution failed for task ':fmd:genJaxb'. > java.lang.NoClassDefFoundError: javax/xml/bind/JAXBContext
build.gradle:
configurations {
jaxb
}
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = "x.wsdl"
outputs.dir classesDir
doLast() {
project.ant {
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
classpath: configurations.jaxb.asPath
mkdir(dir: sourcesDir)
mkdir(dir: classesDir)
xjc(destdir: sourcesDir, schema: schema,
package: "hello.wsdl") {
arg(value: "-wsdl")
produces(dir: sourcesDir, includes: "**/*.java")
}
javac(destdir: classesDir, source: 1.10, target: 1.10, debug: true,
debugLevel: "lines,vars,source",
classpath: configurations.jaxb.asPath) {
src(path: sourcesDir)
include(name: "**/*.java")
include(name: "*.java")
}
copy(todir: classesDir) {
fileset(dir: sourcesDir, erroronmissingdir: false) {
exclude(name: "**/*.java")
}
}
}
}
}
dependencies {
compile "javax.xml.bind:jaxb-api:2.3.1"
compile(files(genJaxb.classesDir).builtBy(genJaxb))
jaxb "com.sun.xml.bind:jaxb-xjc:2.3.1"
}
环境:
Java 10.0.2
Gradle 4.10.2
答案 0 :(得分:1)
有了此依赖项列表,构建终于成功了:
dependencies {
compile(files(genJaxb.classesDir).builtBy(genJaxb))
jaxb "com.sun.xml.bind:jaxb-xjc:2.3.1"
jaxb "com.sun.xml.bind:jaxb-impl:2.3.1"
jaxb "javax.xml.bind:jaxb-api:2.3.1"
jaxb "org.glassfish.jaxb:jaxb-core:2.3.0.1"
}