Gradle Review (8) behavior in-task

Source: Internet
Author: User
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.