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'
}
}
- 执行task
>gradle compile
:compile
compiling source
- 执行多个task
>gradle dist test
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution
每个task只会执行一次,所以 gradle test test 执行效果和 gradle test一样
- 移除tasks
>gradle dist -x test
:compile
compiling source
:dist
building the distribution
- 选择执行脚本
subdir/myproject.gradle
task hello {
doLast {
println "using build file '$buildFile.name' in '$buildFile.parentFile.name'."
}
}
执行
> gradle -q -b subdir/myproject.gradle hello
using build file 'build.gradle' in 'subdir'.
- 选择执行目录
> gradle -q -p subdir hello
using build file 'build.gradle' in 'subdir'.
6.生成profile文件
>gradle test --profile