gpt4 book ai didi

ant - 使用 gradle-script-kotlin 中的 ant 任务

转载 作者:行者123 更新时间:2023-12-02 12:17:08 27 4
gpt4 key购买 nike

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

我可以像这样扩展它吗?

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

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

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

我知道如何在 Groovy 中做到这一点:How do I apply a patch file in Gradle?

最佳答案

AntBuilder继承自 Groovy 的 AntBuilder .您可以通过使用 invokeMethod 并提供所需的任务作为第一个参数并将要绑定(bind)的属性作为映射在第二个参数中。

例如,对于您的补丁用例 (available properties documentation),Kotlin 可能如下所示:

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

关于ant - 使用 gradle-script-kotlin 中的 ant 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40791793/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com