Accessing tasks as project properties

Each task that we add is also available as a project property, and we can reference this property like we can reference any other property in our build script. We can, for example, invoke methods or get and set the property values of our task through the property reference. This means that we are very flexible in how we create our tasks and add behavior to the tasks. In the following script, we use the project property reference to a task to change the description property:

// Create a simple task. task simple << { task -> println "Running ${task.name}" } // The simple task is available as // project property. simple.description = 'Print task name' // We can invoke methods from the // Task object. simple.doLast ...

Get Gradle Effective Implementations Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.