Adding additional properties to tasks

A task object already has several properties and methods. However, we can add any arbitrary new property to a task and use it. Gradle provides an ext namespace for the task object. We can set new properties and use them again once they are set. We can either set a property directly or use a closure to set a property with a value. In the following sample, we print the value of the message task property. The value of the property is assigned with the simple.ext.message = 'world' statement:

// Create simple task. 
task simple << { 
    println "Hello ${message}" 
} 
 
// We set the value for 
// the non-existing message 
// property with the task extension 
// support. 
simple.ext.message = 'world' 

When we run the task, we get the following output:

:simple
Hello world
BUILD SUCCESSFUL
Total time: 0.584 secs
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.205.235