Gradle Extra Properties: Difference between revisions
Jump to navigation
Jump to search
Line 3: | Line 3: | ||
=Overview= | =Overview= | ||
Extra properties allow defining variables that are used multiple times within the same script, such as a file that is referred from multiple locations of the build script. An extra property is a user-defined variable. | Extra properties allow defining variables that are used multiple times within the same script, such as a file that is referred from multiple locations of the build script. An extra property is a user-defined variable. Internally, these properties are stored as key-value pairs in a map, associated with the project. | ||
To add properties, use the "ext" namespace: | |||
<syntaxhighlight lang='groovy'> | |||
ext { | |||
color = 'blue' | |||
} | |||
project.color = 'red' | |||
task displayColor { | |||
doLast { | |||
println color | |||
} | |||
} | |||
</syntaxhighlight> | |||
For the above example, './gradlew displayColor' will display "red". |
Revision as of 03:37, 5 October 2020
Internal
Overview
Extra properties allow defining variables that are used multiple times within the same script, such as a file that is referred from multiple locations of the build script. An extra property is a user-defined variable. Internally, these properties are stored as key-value pairs in a map, associated with the project.
To add properties, use the "ext" namespace:
ext {
color = 'blue'
}
project.color = 'red'
task displayColor {
doLast {
println color
}
}
For the above example, './gradlew displayColor' will display "red".