在命令行中使用Gradle
示例腳本
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í)行任務(wù):
gradle dist
排除某個任務(wù)
gradle dist -x test
用簡寫的任務(wù)名稱
gradle di
只要以“di”開頭的任務(wù)只有一個,就可以這樣執(zhí)行,不一定非得是任務(wù)的完整名稱。
不光這樣,還可以用 gradle compTest
或者even gradle cT
來執(zhí)行compileTest任務(wù)。
指定執(zhí)行的腳本文件
subdir/myproject.gradle:
task hello {
doLast {
println "using build file '$buildFile.name' in '$buildFile.parentFile.name'."
}
}
可以在上級目錄中這樣來執(zhí)行這個腳本文件:
gradle -q -b subdir/myproject.gradle hello
這里的
-q
是說只打印錯誤日志,其他信息類日志不打印
-b
是指定目錄,用-p
還可以指定項目名稱:
gradle -q -p subdir hello
忽略UP-TO-DATE檢查
> gradle --rerun-tasks doIt