我正在使用教程https://spring.io/guides/gs/producing-web-service/#initial來嘗試生成SOAP Web服務。我正在使用Gradle來管理我的依賴關係。Gradle構建失敗
我有一個.xsd文件,它指定了我想要gradle創建的某些類。
然而,當我嘗試在Eclipse中的build.gradle文件運行gradle這個構建我得到以下錯誤:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\zekucukkose\workspace2\gs-producing-web-service-initial\build.gradle'
line: 32
* What went wrong:
A problem occurred evaluating root project 'gs-producing-web-service-initial'.
> Could not find method jaxb() for arguments [com.sun.xml.bind:jaxb-xjc:2.2.4-1]
on root project 'gs-producing-web-service-initial'.
第27行到34如下:
27 dependencies {
28 compile("org.springframework.boot:spring-boot-starter-web")
29 compile("org.springframework.boot:spring-boot-starter-ws")
30 testCompile("org.springframework.boot:spring-boot-starter-test")
31 compile("wsdl4j:wsdl4j:1.6.1")
32 jaxb("com.sun.xml.bind:jaxb-xjc:2.2.4-1")
33 compile(files(genJaxb.classesDir).builtBy(genJaxb))
34 }
就我所知,jaxb是用來生成實際類的。
如果有人可以幫忙,我會很感激。 感謝
這是整個腳本:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-producing-web-service'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-ws")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile("wsdl4j:wsdl4j:1.6.1")
jaxb("com.sun.xml.bind:jaxb-xjc:2.2.4-1")
compile(files(genJaxb.classesDir).builtBy(genJaxb))
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schema = "src/main/resources/countries.xsd"
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) {
arg(value: "-wsdl")
produces(dir: sourcesDir, includes: "**/*.java")
}
javac(destdir: classesDir, source: 1.6, target: 1.6, 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")
}
}
}
}
}
configurations {
jaxb
}
jar {
baseName = 'gs-producing-web-service'
version = '0.1.0'
from genJaxb.classesDir
}
從命令行啓動gradle時是否顯示錯誤?在構建過程中,您期望使用哪個版本的JDK?您是否確定在每種情況下都使用適當的JAVA_HOME啓動gradle? –
嗨Jorge_b,我有一個eclipse的gradle插件,所以我沒有從命令行運行。我正在使用JDK 1.8,並已設置使用它。還有其他建議嗎?謝謝,Zeki。 – Zekik64