我正在创建一个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
中的另一个参数会更好,因此不需要单独定义。那可行吗?
注意:正常的任务定义可以执行此操作
task myTask(dependsOn: 'compile') {
doLast {
println 'I am not affected'
}
}
但我无法做到
testCoverageVerificationTask(dependsOn: "myDependentTask") {
myreport = "testing report"
}
答案 0 :(得分:1)
使用:
Task task = project.tasks.create('testCoverageVerification', TestCoverageVerificationTask)
task.dependsOn("compile")