2016-03-15 76 views
2

我試圖使用gradle插件http://cxf.apache.org/docs/overview.htmlwadl文件生成java代碼。依賴似乎正確解決,但當我調用wadl2java時,我得到Could not find method wadl2java()。所以我想知道爲什麼我得到這個錯誤(因爲它應該存在,查看這個插件的其他maven和命令行示例)以及這個插件應該如何使用?任何幫助真的很感激。爲Gradle配置wadl2java插件

曾試圖在這個領域做一些研究,但似乎沒有這方面的太多信息。從我的gradle這個文件

片段

buildscript { 
    repositories { 
     mavenCentral() 
    } 

    dependencies { 
     classpath "org.apache.cxf:cxf-wadl2java-plugin:3.1.5" 
    } 
} 

// Results in 'Could not find method error' 
wadl2java { 
} 

回答

1

時候晚了,但因爲我還不能對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' 
     } 
    } 
}} 
+0

有趣的解決方案,但是如果你對這個問題的另一種方法感興趣,你可以查看我自己的答案,我終於做到了。 – Robert

0

結束了使用的wadl2java.bat直接指揮在自己的任務線。

task wadl2java(type:Exec) { 
    description = 'Generate java files from WADL file using the wadl2java tool' 
    workingDir = "$projectDir/apache-cxf-3.1.5/bin/" 
    commandLine 'cmd', '/c', 'wadl2java.bat', '-verbose', '-p', "com.your.package", '-d', "$projectDir/src/main/java", "-xjc -b $path/to/your/bindings" , "$path/to/your/wadl" 
}