Read Gradle script (6)-Hello Groovy, Goodbye getters&setters

Source: Internet
Author: User

This article is very simple, that is, the following Gradle script back to the prototype:

Version = 1.0

Groovy Syntax sugar

Java programmers are certainly not unfamiliar with JavaBeans and getter/setter methods, so they don't introduce much. Although modern Ides provide shortcuts that make it easy to generate getter and setter methods for fields, I still hate them. Fortunately, there is groovy grammar sugar in hand, you can say goodbye to the Getter/setter Method! The above script is actually the Setversion method that calls the project interface:

Project.setversion (1.0)
The project interface also defines the GetVersion method, so we can get the version information of the item in the following way:

println project.version//Groovyprintln (Project.getversion ())//Java

Set task properties

Then look at the following script:

Task HelloWorld {    group = ' MyTasks '    description = ' Prints Hello World '    . dolast {        println ' Hello world! '    }}
Well, the point is that the task Configuring Closures, we can Implicitof the control task. GroupAnd Description, just the two properties of the task:

public void Setgroup (string group) public string Getgroup () public void stdescription (string description) public string get Description ()

Conclusion

Gradle's domain objects , most of which provide a lot of properties (i.e. getter and setter), in the build script, we can easily set and access these properties.


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.