behaviour
When I was studying, I said, you can add behavior to the task behaviour, take a look at the following example:
Task Hello << {
println ' Hello Earth '
}
hello.dofirst {
println ' Hello Venus '
}
Hello << {
println ' Hello Jupiter '
}
hello.dolast {
println ' Hello Mars '
}
The output is as follows:
d:\gradle_product\0123>gradle-q Hello
Hello Venus
hello Earth
hello Jupiter
Hello Mars
Dofirst and Dolast These are behaviors that represent some of the additional behavior of the Hello task that you define, and different levels of behavior are not related to the order you define in Build.gradle, but the same level has a relationship, and whoever defines it first executes that part first.
different grades
For example, we swap the positions of Dofirst and dolast to see the order of execution:
Task Hello << {
println ' Hello Earth '
}
Hello << {
println ' Hello Jupiter '
}
hello.dolast {
println ' Hello Mars '
}
hello.dofirst {
println ' Hello Venus '
}
Output:
d:\gradle_product\0123>gradle-q Hello
Hello Venus
hello Earth
hello Jupiter
Hello Mars
After practical verification, the output is unchanged.
Same Level
For example, the behavior defined by Hello.dolast and hello<< is the same level, and is executed after the Hello task executes. The order of execution at this time is related to the order you define, for example, we move the hello<< above to Dolast.
Task Hello << {
println ' Hello Earth '
}
hello.dolast {
println ' Hello Mars '
}
Hello << {
println ' Hello Jupiter '
}
hello.dofirst {
println ' Hello Venus '
}
Output:
d:\gradle_product\0123>gradle-q Hello
Hello Venus
hello Earth
hello Mars
Hello Jupiter