使用gradle-script-kotlin的ant任务

我如何从我的build.gradle.kts脚本访问ant任务? 特别是,我对ant.patch任务感兴趣。

我可以像这样扩展它吗?

 task("patchSources", Patch::class) { 

我可以从其他任务调用它,像这样吗?

 task("patchSources") { doLast { ant.patch(...) } } 

我知道如何在Groovy中做到这一点: 如何在Gradle中应用补丁文件?

这适用于我:

 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() } } } 

我不确定这是否是唯一的方法。