執(zhí)行多個tasks
可以在命令中執(zhí)行多個task任務(wù)靶剑,比如,可以執(zhí)行
gradle complie test
這將會執(zhí)行compile和test的任務(wù)。gradle不僅會執(zhí)行他們自己的任務(wù)暴浦,還會執(zhí)行所依賴的任務(wù),每一個任務(wù)僅僅執(zhí)行一次晓锻,不管他在在命令行中怎么特殊歌焦,或者作為一個依賴給其他的task⊙舛撸看一個列子
task compile {
doLast {
println 'compiling source'
}
}
task compileTest(dependsOn: compile) {
doLast {
println 'compiling unit tests'
}
}
task test(dependsOn: [compile, compileTest]) {
doLast {
println 'running unit tests'
}
}
task dist(dependsOn: [compile, test]) {
doLast {
println 'building the distribution'
}
}
執(zhí)行g(shù)radle dist test
> gradle dist test
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution
BUILD SUCCESSFUL
Total time: 1 secs
在上面定義的task中独撇,dist和test都依賴了compile的task,執(zhí)行命令后,compile的task只執(zhí)行了一次纷铣。
image
排除task
可以使用 -x 命令來排除需要執(zhí)行的task卵史,
> gradle dist -x test
:compile
compiling source
:dist
building the distribution
BUILD SUCCESSFUL
Total time: 1 secs
從輸出來看,test指令已經(jīng)被排除了搜立,并沒有執(zhí)行以躯。