如何在Kotlin DSL中本地运行wsgen ant任务?

时间:2019-05-15 22:10:02

标签: jenkins gradle kotlin wsgen

我正在将现有的基于Groovy的gradle任务转换为kotlin,以下方法非常缓慢。到目前为止,我还有其他方法吗?

tasks.register("generateWsdls") {
    dependsOn("someJavaCompileTask")
    description = "Runs wsgen on endpoint classes."
    group = "Source Generation"

    val destinationDir = "$projectDir/output/service"
    val classesDir = "$projectDir/build/classes/main"
    val classesRelativePath = "api/classes"
    val wsdlsToGenerate = fileTree(classesRelativePath) {include("**/*_api.class")}
    val taskCp = sourceSets.getAt("main").runtimeClasspath.asPath
    val cp = (sourceSets.getAt("main").runtimeClasspath + files(classesRelativePath) + files("api/java")).asPath

    outputs.dir(destinationDir)
    inputs.files("classesRelativePath")
    doLast {
        mkdir(classesDir)
        mkdir(destinationDir)
        // This works but is there a better way to deletage this task in Kotlin?
        ant.withGroovyBuilder {
            "taskdef"(
                    "name" to "wsgen",
                    "classname" to "com.sun.tools.ws.ant.WsGen",
                    "classpath" to taskCp
            )
            wsdlsToGenerate.forEach {
                val className = relativePath(it)
                        .replace("[\\\\/]".toRegex(), ".")
                        .replace("api.classes.", "")
                        .replace(".class", "")
                println("[wsgen] $className")
                "wsgen"(
                    "classpath" to cp,
                    "verbose" to false,
                    "genwsdl" to true,
                    "resourcedestdir" to destinationDir,
                    "sourcedestdir" to "api/java",
                    "keep" to true,
                    "sei" to className                      
                )
            }
        }
    }
}

目前大约需要7分钟来处理约80个wsdls。

0 个答案:

没有答案