時候晚了,但因爲我還不能對SO,我在這裏放下解決方案找到答案。
這運行相同工具的命令行版本。你嘗試的是gradle中不支持的maven插件。
(你可能不需要所有我已經添加的依賴關係。)
dependencies {
compile group: 'javax.xml', name: 'jaxrpc', version: '1.1'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.3'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3.5'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile 'joda-time:joda-time:2.9.7'
compile group: 'org.apache.cxf', name: 'cxf-rt-frontend-jaxws', version: '3.1.10'
compile group: 'org.apache.cxf', name: 'cxf-rt-transports-http-jetty', version: '3.1.10'
compile 'org.apache.cxf:cxf-tools:3.1.10'
compile group: 'org.apache.cxf.xjc-utils', name: 'cxf-xjc-runtime', version: '3.1.0'
compile group: 'org.apache.cxf', name: 'cxf-wadl2java-plugin', version: '3.1.10'
compile group: 'org.apache.cxf', name: 'cxf-tools-wadlto', version: '3.1.10'
compile("org.projectlombok:lombok:1.16.12")
testCompile 'junit:junit:4.12'
testCompile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'}
project.ext {
wadlDir = file("$projectDir/src/main/resources")
generatedWadlDir = file("build/generated-sources")
wadlsToGenerate = [['src/main/resources/your_wadl_file.wadl']]}
task wadl2Java() {
println "Deleting auto generated files.."
if(!project.buildDir.exists()) {
project.buildDir.mkdirs()
}
def subdir = new File(project.buildDir, "generated-sources")
if(!subdir.exists()) {
subdir.mkdirs()
}
file(subdir).list().each{
f -> delete "${subdir}/${f}"
}
if (!wadlDir.listFiles()) {
// do nothing
} else {
inputs.files wadlDir.listFiles()
outputs.files generatedWadlDir
doLast {
wadlsToGenerate.each { argsin ->
argsin.add(argsin.size - 1, '-d')
argsin.add(argsin.size - 1, generatedWadlDir)
javaexec {
classpath = configurations.runtime
main = 'org.apache.cxf.tools.wadlto.WADLToJava'
args = argsin
systemProperties = ['exitOnFinish': 'TRUE']
}
}
println "Copy auto generated files.."
copy {
from generatedWadlDir
into 'src/main/java'
}
}
}}
有趣的解決方案,但是如果你對這個問題的另一種方法感興趣,你可以查看我自己的答案,我終於做到了。 – Robert