Gradle 并不真正遵守执行顺序
Gradle doesn't really honor execution order
我有一个 Gradle 构建 3 个任务,第一个应该设置部署类型 (test/staging/production),第二个只是一个显示当前类型的助手。第三个实现实际部署(实际上对于这个问题并不那么重要)。像这样:
task toTest() {
project.ext.set('deployType', 'test')
println "Set deploy type: ${project.deployType}"
}
task showStatus() {
mustRunAfter = ['toTest', 'toStage', 'toProd']
println "Curr deploy type: ${project.deployType}"
}
task deploy(dependsOn: [toTest, showStatus]) {
...
}
Gradle 说它按以下顺序运行的问题:toTest
-> showStatus
-> deploy
。但正如我从控制台看到的那样,它使用不同的顺序:
////....initial tasks
:buildSrc:build UP-TO-DATE
Curr deploy type: local
Set deploy type: test
:toTest UP-TO-DATE
////.......a lot of other tasks
:showStatus UP-TO-DATE
////... final deployment
我看到两个相反的事情:执行顺序是 toTest
->showStatus
,但输出首先来自 showStatus
,然后才来自 toTest
。这怎么可能?我做错了什么?
Gradle 2.2
PS 另外,似乎 project.ext
只是被忽略了,或者其他任务中看不到值。但似乎这是另一个问题的主题。
任务定义中的代码会在 "read" 时执行,如果您想在任务运行 make "last" 时完成操作。 (对于 doLast
,<<
是 shorthand)例如
task toTest() {
project.ext.set('deployType', 'test')
}
toTest << {
println "Set deploy type: ${project.deployType}"
}
task showStatus() {
mustRunAfter = ['toTest']
}
showStatus << {
println "Curr deploy type: ${project.deployType}"
}
task lerl(dependsOn: [toTest, showStatus]) {
println "lerl"
}
给予
lerl
:toTest
Set deploy type: test
:showStatus
Curr deploy type: test
:lerl
我有一个 Gradle 构建 3 个任务,第一个应该设置部署类型 (test/staging/production),第二个只是一个显示当前类型的助手。第三个实现实际部署(实际上对于这个问题并不那么重要)。像这样:
task toTest() {
project.ext.set('deployType', 'test')
println "Set deploy type: ${project.deployType}"
}
task showStatus() {
mustRunAfter = ['toTest', 'toStage', 'toProd']
println "Curr deploy type: ${project.deployType}"
}
task deploy(dependsOn: [toTest, showStatus]) {
...
}
Gradle 说它按以下顺序运行的问题:toTest
-> showStatus
-> deploy
。但正如我从控制台看到的那样,它使用不同的顺序:
////....initial tasks
:buildSrc:build UP-TO-DATE
Curr deploy type: local
Set deploy type: test
:toTest UP-TO-DATE
////.......a lot of other tasks
:showStatus UP-TO-DATE
////... final deployment
我看到两个相反的事情:执行顺序是 toTest
->showStatus
,但输出首先来自 showStatus
,然后才来自 toTest
。这怎么可能?我做错了什么?
Gradle 2.2
PS 另外,似乎 project.ext
只是被忽略了,或者其他任务中看不到值。但似乎这是另一个问题的主题。
任务定义中的代码会在 "read" 时执行,如果您想在任务运行 make "last" 时完成操作。 (对于 doLast
,<<
是 shorthand)例如
task toTest() {
project.ext.set('deployType', 'test')
}
toTest << {
println "Set deploy type: ${project.deployType}"
}
task showStatus() {
mustRunAfter = ['toTest']
}
showStatus << {
println "Curr deploy type: ${project.deployType}"
}
task lerl(dependsOn: [toTest, showStatus]) {
println "lerl"
}
给予
lerl
:toTest
Set deploy type: test
:showStatus
Curr deploy type: test
:lerl