我是gradle的新手。如何运行exec一个接一个的任务?我有一个问题,任务test1在android.applicationVariants.all之前运行,属性测试为空,如何更改?
项目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)
答案 0 :(得分:4)
定义了两个任务:
task mainTask {
println "main"
}
task nextTask {
println "next task"
}
以下代码
mainTask << {
nextTask.execute()
}
在nextTask
运行后执行mainTask
:
> gradle mainTask
main
next task
答案 1 :(得分:3)
1)使用dependsOn来处理层次结构:
task helloTask1 << {
println "hello task 1"
}
task helloTask2(dependsOn: helloTask1) {
println "hello task 2"
}
然后,调用helloTask2 execustion将首先触发helloTask1
2)如果需要,使用mustRunAfter()(此方法处于孵化模式):
task helloTask1 {
println "hello task 1"
}
task helloTask2 {
mustRunAfter helloTask1
println "hello task 2"
}
答案 2 :(得分:1)
查看task's mustRunAfter方法。