为gradle配置wadl2java插件

时间:2016-03-15 09:45:24

标签: java gradle

我尝试使用gradle插件http://cxf.apache.org/docs/overview.htmlwadl文件生成java代码。依赖性似乎得到了正确解决,但是当我调用wadl2java时,我得到了Could not find method wadl2java()。因此,我想知道为什么我会收到此错误(因为它应该存在,查看此插件的其他maven和命令行示例)以及该插件应该如何使用?任何帮助都非常感谢。

曾尝试在这个领域做过一些研究,但似乎没有太多关于此的信息。

我的gradle文件中的代码段

buildscript {
    repositories {  
        mavenCentral()
    }

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

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

2 个答案:

答案 0 :(得分:1)

现在已经很晚了,但由于我也找不到答案,所以我在这里提出解决方案。

这将运行同一工具的命令行版本。您尝试的是maven插件,gradle不支持。

(你可能不需要我添加的所有依赖项。)

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'
        }
    }
}}

答案 1 :(得分: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"
}