Learn Java

Task Properties

Demo

build.gradle :

task myTask {
    ext.myProperty = "myValue"
}

task printTaskProperties << {
    println myTask.myProperty
}

Run command gradle -q printTaskProperties to see the result:

myValue

ExtraPropertiesExtension

ext -> ExtraPropertiesExtension : API Documentation

Extra properties extensions allow new properties to be added to existing domain objects. They act like maps, allowing the storage of arbitrary key/value pairs. All ExtensionAware Gradle domain objects intrinsically have an extension named ext of this type.

An important feature of extra properties extensions is that all of its properties are exposed for reading and writing via the ExtensionAware object that owns the extension.

extra.gradle :

task test{
    project.ext.set("myProp", "myValue")

    println '1' + project.myProp

    project.myProp = "anotherValue"

    println '2' + project.myProp
    println '3' + project.ext.get("myProp")
}

Run command gradle -q -b extra.gradle test to see the result:

1myValue
2anotherValue
3anotherValue