Gradle.properties: Difference between revisions
No edit summary |
|||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[ | * [[Gradle Properties - Runtime and Project Configuration|Gradle Properties - Runtime and Project Configuration]] | ||
=Overview= | =Overview= | ||
'gradle.properties' files are used to define configuration [[ | 'gradle.properties' files are used to define configuration [[Gradle Properties - Runtime and Project Configuration#Overview|properties]]. gradle.properties files can be present in two layers: the [[#Gradle_User_Home_gradle.properties|user home directory .gradle directory]] and the [[#Project_Root_gradle.properties|project root]]. Property keys must comply with the rules described here: [[Gradle Properties - Runtime and Project Configuration#Property_Keys|Property Keys]]. | ||
=Hierarchy= | =Hierarchy= |
Revision as of 22:06, 13 October 2020
Internal
Overview
'gradle.properties' files are used to define configuration properties. gradle.properties files can be present in two layers: the user home directory .gradle directory and the project root. Property keys must comply with the rules described here: Property Keys.
Hierarchy
Gradle User Home gradle.properties
This file is stored in Gradle user home directory ~/.gradle/gradle.properties, conventionally referred to as GRADLE_USER_HOME. Any property declared in this file will be available to all user's Gradle projects.
Project Root gradle.properties
Conventionally, this is where the version of the project is stored:
version=1.0-SNAPSHOT
This file is important because it can be stored in source control, so the entire team working on the project can share the same configuration.
Multi-Project Builds
Each project of a multi-project build can maintain a gradle.properties file in its root.
Precedence Rules
If files from both layers are present, their content is merged and the configuration that comes from the user home directory takes precedence over the configuration that comes from the project root directory. This makes sense from a security perspective, as the user home directory is not checked in into a repository while the project is, and we need to store security sensitive configuration. When the same property is declared in both root project and a sub-project's gradle.properties files, the value coming from the sub-project takes precedence over the root project value.
Projection
The properties configured in gradle.properties files are flattened according the precedence rules described above and projected into the Project instance where they can be accessed as project properties, similarly to extra properties.
gradle.properties:
my.color=blue
build.properties:
println project.my.color
If gradle.properties declares:
shape = 'square'
the configured value can be accessed from the project (build.gradle) simply using the property name:
task display {
doLast {
// equivalent property references
println project.shape
println shape
}
}