table of Contents
- A Profile
- Two practice
- # 2.5 manipulation tasks
- Three command-line practice (b)
- More than 3.1 task execution
- 3.2 Troubleshooting Tasks
- 3.3 Ignore, Fail
- 3.4 Task initials
- 3.5 Construction of the specified build configuration file / screen type other auxiliary output / multi-project
- 3.6 enforce task execution
- 3.7 View build information
- reference
A Profile
Apache Ivy dependency management is based, tasks, and is based on the ant build script with the groovy
Wrapper Gradle
Gradle wrapper allows you to install on machines without an execution Gradle build, it is very useful for sustained release, for some minimum requirements for open source projects built shield is also very useful, wrapper for enterprises is very importantly, the client machine can manage 0, and 强制了Gradle的版本
allows a lower error rate
See: Gradle learning (a) - Introduction
Two practice
See: http://wiki.jikexueyuan.com/project/gradle/build-script-basics.html
2.1 helloworld
task hello {
doLast {
println 'Hello world!'
}
}
run
gradle -q hello
Introduction mode (no <<)
task hello {
println 'Hello world!'
}
2.2 task dependencies
task hello {
doLast{
println 'Hello world!'
}
}
task intro(dependsOn: hello) {
doLast{
println "I'm Gradle"
}
}
Why use doLast?
<< was removed after 5.0, rather than written words. The task will be performed sequentially.
2.3 dependent delay
Ie dependencies written on the back
task intro(dependsOn: 'hello') {//注意:当引用的任务尚未定义的时候不可使用短标记法来运行任务。
doLast{
println "I'm Gradle"
}
}
task hello {
doLast{
println 'Hello world!'
}
}
2.4 Dynamic Task
4.times { counter ->//这里构建了4个任务,这应该时Groovy的遍历语法
task "task$counter" {//这里是双引号
doLast{
println "I'm task number $counter"
}
}
}
# 2.5 manipulation tasks
Once the task is 创建
later to be passed between the tasks API 进行相互访问
. This is the difference from the Ant. For example, you can increase the number of dependent
2.5.1 increased reliance
4.times { counter ->
task "task$counter" {
doLast{
println "I'm task number $counter"
}
}
}
task0.dependsOn task2, task3
2.5.2 task behavior increased
task hello {
doLast{
println 'Hello Earth'
}
}
hello.doFirst {
println 'Hello Venus'
}
hello.doFirst {
println 'Hello Venus repeat'
}
hello.doLast {
println 'Hello Mars'
}
hello {
doLast{
println 'Hello Jupiter'
}
}
//doFirst后的先,doLast后的后。即后面的会覆盖前面
Hello Venus repeat
Hello Venus
Hello Earth
Hello Mars
Hello Jupiter
doFirst and doLast can be called multiple times. They are added at the beginning and end of the task. When the task begins execution of these actions will be carried out according to the established order
2.5.3 short notation
You would have noticed it, yes, each task is a script property, you can access it:
To access task properties
task hello {//这里有task
doLast{
println 'Hello Earth'
}
}
hello.doLast {//必须先声明task
println "Greetings from the $hello.name task."
}
2.6 to add custom properties
You can add additional properties for a task. For example, add a property called the myProperty with ext.myProperty way to give him an initial value. This increases a custom attribute.
task hello {
doLast{
println 'Hello Earth'
}
ext.myProperty = "myValue"
}
task printTaskProperties {
doLast{
println hello.myProperty
}
}
2.7 calls Ant task
slightly
2.8 define the default task
task hello {
doLast{
println 'Hello Earth'
}
ext.myProperty = "myValue"
}
task printTaskProperties {
doLast{
println hello.myProperty
}
}
defaultTasks 'hello', 'printTaskProperties'
Three command-line practice (b)
Reference: Gradle Learning (II) - Command Line
More than 3.1 task execution
gradle can perform multiple tasks simultaneously commands, parameters of the task list, the parameter list of tasks executed sequentially, e.g. gradle compile test, compile and test tasks will be executed tasks, including the task dependency test, but the point is to note , the same task will be executed once , either in the task list, or a list of tasks dependent tasks 同一个任务只会执行一次
.
3.2 Troubleshooting Tasks
gradle dist -x test
dist task depends on the test task , but using ** - after x test did not perform the task **, test dependent compileTest tasks did not execute, test also depends on compile task, but the compile will also be dependent dist, and has not ruled out Therefore compile executed.
3.3 Ignore, Fail
-continue
parameter
3.4 Task initials
Support abbreviation (minimum of two characters)
support hump (cT)
3.5 Construction of the specified build configuration file / screen type other auxiliary output / multi-project
Specifying the build profile: -b
build file to be executed ( -b=--build-file
)
shield Other Auxiliary Output: -q tag type is used to shield the other auxiliary outputs, only the output of the output task stream or error stream (-q = -quiet)
multi-item Construction :-p instruction (-p = -project-dir), commonly used to construct a plurality of items, of course, the file name to use the default buil.gradle
be used in combination
gradle -q -p subfile -b secondbuild.gradle cT
3.6 enforce task execution
untested
> gradle --rerun-tasks jar
BUILD SUCCESSFUL in 7s
4 actionable tasks: 4 executed
3.7 View build information
We first need a gradle project
slightly