2016-11-24 48 views

回答

1

這個工作對我來說:

import org.apache.tools.ant.taskdefs.Patch 

val patchConfigTask = task("patchConfig") { 
    dependsOn(unzipTask)  

    doLast { 
     val resources = projectDir.resolve("src/main/resources") 
     val patchFile = resources.resolve("config.patch") 

     Patch().apply { 
      setPatchfile(patchFile) 
      setDir(buildDir.resolve("config/")) 
      setStrip(1) // gets rid of the a/ b/ prefixes 
      execute() 
     } 
    } 
} 

我不知道,如果它是一個正確的路到做 - 它。

0

AntBuilder從Groovy的AntBuilder延伸。您可以使用invokeMethod將groovy(如ant.patch())中的動態方法調用翻譯爲Kotlin,並將所需任務作爲第一個參數提供,並將屬性作爲第二個參數中的映射進行綁定。

例如,對於您的補丁用例(available properties documentation)的科特林看起來是這樣的:

val patchSources by tasks.creating { 
    doLast { 
    ant.invokeMethod("patch", mapOf(
     "patchfile" to patchFile, 
     "dir" to configDir, 
     "strip" to 1 
    )) 
    } 
}