gpt4 book ai didi

gradle - 在 Gradle 中概括 compile* 任务

转载 作者:行者123 更新时间:2023-12-03 03:53:42 25 4
gpt4 key购买 nike

如何在多语言项目中概括“编译”任务?
例如。我可以将其概括为在所有 compile* 上运行使用的每种语言的任务。

compileJava {
ajc {
enabled = true
classpath = configurations.aspectj
options {
aspectpath = configurations.aspect
compilerArgs = []
}
}
}
compileTestJava {
ajc {
enabled = true
classpath = configurations.aspectj
options {
aspectpath = configurations.testAspect
compilerArgs = []
}
}
}
来源: FreeFair Gradle Plugin Collection
如何修改以上内容,使其可以与任何 compile* 一起运行任务,例如 compileGroovy , compileKotlin , compileScala等在多语言项目中?

最佳答案

您可以使用方法matching(...) TaskContainer 可通过 tasks 获得在您的 build.gradle :

tasks.matching { task -> task.name.startsWith('compile') }.all {
ajc {
enabled = true
classpath = configurations.aspectj
options {
aspectpath = configurations.testAspect
compilerArgs = []
}
}
}
请注意,此解决方案仅适用于所有以 'compile' 开头的任务。实际上有一个分机 ajc .它也只因为 Groovy 而有效,就像 afc是否可用将动态评估。这在 Kotlin 构建脚本中不起作用。

关于gradle - 在 Gradle 中概括 compile* 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63879063/

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