Gradle Variables and Properties

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

Concepts

Properties

The effective value of the properties can be displayed with:

gradle properties

System Properties

Gradle Properties

Project Properties

Where are These Properties Provided

These configuration methods are listed in the descending order of their precedence, with the highest precedence at the top. The first one encountered wins.

Command Line Flags

Command line flags have precedence over properties and environment variables with the same effect. See:

Gradle Command Line

Command Line Property Definitions

-D

-P defines project properties.

gradle.properties Files

gradle.properties can be used to define properties for the build. gradle.properties files can be placed either in Gradle user home directory (~/.gradle/gradle.properties) or in the project root directory. If both files 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. If a command line -Dproperty-name=... is specified, the value overrides the value read from the property files, if any.

Form a security perspective, it makes sense to use the user home directory if the project is checked into a repository and we do not want to maintain sensitive information in that file.

someUser=someuser
somePassword=somepassword

Gradle User Home gradle.properties

Project Root

Environment Variables

Environment variables such as GRADLE_OPTS and JAVA_OPTS are sourced by the environment that executes Gradle. These environment variables can be used to provide properties definition, but they are only available in a specific user's environment, and do not propagate to version control. For definitions that propagate to version control, so an entire team can use them, use the project root gradle.properties.

TODO

tmp