我是 gradle 的新手。我怎样才能一个接一个地运行 exec 任务?我遇到一个问题,任务test1在android.applicationVariants.all之前运行,属性test为空,如何更改?
项目A
String test = ''
android {
android.applicationVariants.all.doFirst {
test = 'vasya'
}
task test1.doLast{
println "$test"
}
但是我得到了以下输出:
* Where:
Build file '/home/build.gradle' line: 57
* What went wrong:
A problem occurred evaluating project ':ProjectA'.
> No signature of method: java.util.ArrayList.doFirst() is applicable for argument types: (build_6g09fl113rl613 iaq870b0hod0$_run_closure1_closure12_closure18) values: [build_6g09fl113rl613iaq870b0hod0$_run_closure1_closure12_closure18@5f81a4ab]
Possible solutions: first(), toList(), asList(), sort(), sort(groovy.lang.Closure), sort(boolean)
最佳答案
1) 使用 dependsOn 处理层次结构:
task helloTask1 << {
println "hello task 1"
}
task helloTask2(dependsOn: helloTask1) {
println "hello task 2"
}
那么调用helloTask2执行会先触发helloTask1
2) 如果需要使用 mustRunAfter() (此方法处于孵化模式):
task helloTask1 {
println "hello task 1"
}
task helloTask2 {
mustRunAfter helloTask1
println "hello task 2"
}
关于android - 一个接一个地执行任务。 doFirst,doLast Groovy/Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22530640/