gpt4 book ai didi

gradle - 我可以在带有DependsOn参数的插件中创建gradle任务吗?

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

我正在创建一个gradle插件,如下所示

class MyPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create('testCoverageVerificationTask', TestCoverageVerificationPluginExtension)
project.tasks.create('testCoverageVerification', TestCoverageVerificationTask)
}
}

要使用它,我需要将它们添加到我的build.gradle中
apply plugin: my.package.MyPlugin

testCoverageVerificationTask {
myreport = "testing report"
}

testCoverageVerification.dependsOn "myDependentTask"

但是,我认为最好将 dependsOn作为 testCoverageVerificationTask中的另一个参数,这样就不必单独定义它。那可行吗?

note :正常的任务定义可以做到这一点
task myTask(dependsOn: 'compile') {
doLast {
println 'I am not affected'
}
}

但是我做不到
testCoverageVerificationTask(dependsOn: "myDependentTask") {
myreport = "testing report"
}

最佳答案

使用:

Task task = project.tasks.create('testCoverageVerification', TestCoverageVerificationTask)
task.dependsOn("compile")

关于gradle - 我可以在带有DependsOn参数的插件中创建gradle任务吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46397832/

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