# Configuring the Build Environment

version 8.4

Gradle provides multiple mechanisms for configuring the behavior of Gradle itself and specific projects. The following is a reference for using these mechanisms.

When configuring Gradle behavior, you can use these methods, listed in order of highest to lowest precedence (the first one wins):

Order | Method | Example | Notes
--- | --- | --- | ---
1 | Command-line flags | `--build-cache` | These have precedence over properties and environment variables.
2 | System properties | `systemProp.http.proxyHost=somehost.org` | Stored in a `gradle.properties` file in a root project directory.
3 | Gradle properties | `org.gradle.caching=true` | Typically stored in a `gradle.properties` file in a project directory or in the `GRADLE_USER_HOME`.
4 | Environment variables | `GRADLE_OPTS` | Sourced by the environment that executes Gradle.

## Configuring your build environment

You can configure the build using the same mechanisms.

You can also read information about the environment in the build logic.

## 1. Command-line flags

The command line interface, along with the available flags, is described in its own section.

## 2. System properties

Using the `-D` command-line option, you can pass a system property to the JVM, which runs Gradle.

The `-D` option of the `gradle` command has the same effect as the `-D` option of the `java` command.

You can also set system properties in `gradle.properties` files with the prefix `systemProp`:

    systemProp.gradle.wrapperUser=myuser
    systemProp.gradle.wrapperPassword=mypassword

The following are common system properties:

Gradle Properties

`gradle.wrapperUser=(myuser)`

  Specify username to download Gradle distributions from servers using HTTP Basic Authentication.

`gradle.wrapperPassword=(mypassword)`

  Specify password for downloading a Gradle distribution using the Gradle wrapper.

`gradle.user.home=(path to directory)`

  Specify the `GRADLE_USER_HOME` directory.

The Gradle Properties listed the section below can also be set as system properties.

Networking Properties

`https.protocols`

  Specify the supported TLS versions in a comma-separated format. e.g., `TLSv1.2,TLSv1.3`.

`http.proxyHost`

  The hostname, or address, of the proxy server. Default: `none`.

`http.proxyPort`

  The port number of the proxy server. Default: `80`.

`http.nonProxyHosts`

  Indicates the hosts that should be accessed without going through the proxy. Default: `localhost|127.*|[::1]`.

`https.proxyHost`

  The hostname, or address, of the proxy server. Default: `none`.

`https.proxyPort`

  The port number of the proxy server. Default: `443`.

`socksProxyHost`

  The hostname, or address, of the proxy server. Default: `none`.

`socksProxyPort`

  The port number of the proxy server. Default: `1080`.

`socksProxyVersion`

  The version of the SOCKS protocol supported by the server. Default: `5` for SOCKS V5.

`java.net.socks.username`

  Username to use if the SOCKSv5 server asks for authentication. Default: `none`.

`java.net.socks.password`

  Password to use if the SOCKSv5 server asks for authentication. Default: `none`.

Runtime Environment Properties

`java.runtime.version=(string)`

  JRE version, e.g. `1.7.0_09-b05`.

`java.version=(string)`

  JDK version, e.g., `1.7.0_09`.

`java.home=(string)`

  JRE home directory, e.g., `C:\Program Files\Java\jdk1.7.0_09\jre`.

`java.class.path=(string)`

  JRE classpath e.g., `.` (dot – used for current working directory).

`java.library.path=(string)`

  JRE library search path for search native libraries. Typically taken from the environment variable PATH.

`java.ext.dirs=(string)`

  JRE extension library path(s), e.g, `C:\Program Files\Java\jdk1.7.0_09\jre\lib\ext;C:\Windows\Sun\Java\lib\ext`.

Operating System Properties

`os.name=(string)`

  The OS’s name, e.g., `Windows 7`.

`os.arch=(string)`

  The OS’s architecture, e.g., `x86`.

`os.version=(string)`

  The OS’s version, e.g., `6.1`.

File System Properties

`file.separator=(string)`

  Symbol for file directory separator such as `d:\test\test.java`. Default is '\' for windows or '/' for Unix/Mac.

`path.separator=(string)`

  Symbol for separating path entries, e.g., in PATH or CLASSPATH. Default is ';' for windows or ':' for Unix/Mac.

`line.separator=(string)`

  Symbol for end-of-line (or new line). Default is "\r\n" for windows or "\n" for Unix/Mac OS X.

User Properties

`user.name=(string)`

  The user’s name.

`user.home=(string)`

  The user’s home directory.

`user.dir=(string)`

  The user’s current working directory.

In a multi-project build, `systemProp` properties set in any project except the root will be ignored. Only the root project’s `gradle.properties` file will be checked for properties that begin with `systemProp`.

The following examples demonstrate how to use System properties.

Example 1: Setting system properties with a `gradle.properties` file:

gradle.properties

    systemProp.system=gradlePropertiesValue

Example 2: Reading system properties at configuration time:

init.gradle.kts

    // Using the Java API
    println(System.getProperty("system"))

settings.gradle.kts

    // Using the Java API
    println(System.getProperty("system"))

    // Using the Gradle API, provides a lazy Provider<String>
    println(providers.systemProperty("system").get())

build.gradle.kts

    // Using the Java API
    println(System.getProperty("system"))

    // Using the Gradle API, provides a lazy Provider<String>
    println(providers.systemProperty("system").get())

init.gradle

    // Using the Java API
    println System.getProperty('system')

settings.gradle

    // Using the Java API
    println System.getProperty('system')

    // Using the Gradle API, provides a lazy Provider<String>
    println providers.systemProperty('system').get()

build.gradle

    // Using the Java API
    println System.getProperty('system')

    // Using the Gradle API, provides a lazy Provider<String>
    println providers.systemProperty('system').get()

Example 3: Reading system properties for consumption at execution time:

build.gradle.kts

    tasks.register<PrintValue>("printProperty") {
        // Using the Gradle API, provides a lazy Provider<String> wired to a task input
        inputValue = providers.systemProperty("system")
    }

build.gradle

    tasks.register('printProperty', PrintValue) {
        // Using the Gradle API, provides a lazy Provider<String> wired to a task input
        inputValue = providers.systemProperty('system')
    }

Example 4: Setting system properties from the command line `-D gradle.wrapperUser=username`:

    $ gradle -Dsystem=commandLineValue

## 3. Gradle properties

Gradle provides several options that make it easy to configure the Java process that will be used to execute your build.

While it’s possible to configure these in your local environment via `GRADLE_OPTS` or `JAVA_OPTS`, it is useful to be able to store certain settings like JVM memory configuration and `JAVA_HOME` location in version control so that an entire team can work with a consistent environment.

To do so, place these settings into a `gradle.properties` file and commit it to your version control system.

The final configuration taken into account by Gradle is a combination of all Gradle properties set on the command line and your `gradle.properties` files.

If an option is configured in multiple locations, the first one found in any of these locations wins:

1. command line, set using `-D`.

2. `gradle.properties` in `GRADLE_USER_HOME` directory.

3. `gradle.properties` in the project’s directory, then its parent project’s directory up to the build’s root directory.

4. `gradle.properties` in the Gradle installation directory.

| The location of the `GRADLE_USER_HOME` may have been changed beforehand via the `-Dgradle.user.home` system property passed on the command line.

The following properties can be used to configure the Gradle build environment:

`org.gradle.caching=(true,false)`

  When set to `true`, Gradle will reuse task outputs from any previous build when possible, resulting in much faster builds.

  Default is `false`; the build cache is not enabled.

`org.gradle.caching.debug=(true,false)`

  When set to `true`, individual input property hashes and the build cache key for each task are logged on the console.

  Default is `false`.

`org.gradle.configuration-cache=(true,false)`

  Enables configuration caching. Gradle will try to reuse the build configuration from previous builds.

  Default is `false`.

`org.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=(file path)`

  Used to exclude file system checks on the specified path from configuration cache inputs fingerprinting.

  Default is `null`.

`org.gradle.configuration-cache.inputs.unsafe.ignore.in-serialization=(true,false)`

  Used to ignore inputs in task graph serialization.

  Default is `false`.

`org.gradle.configuration-cache.problems=(fail,warn)`

  Configures how the configuration cache handles problems.

  Set to `warn` to report problems without failing the build.

  Set to `fail` to report problems and fail the build if there are any problems.

  Default is `fail`.

`org.gradle.configuration-cache.max-problems=(# of problems)`

  Configures the maximum number of configuration cache problems allowed as warnings until Gradle fails the build.

  Default is `512`.

`org.gradle.configureondemand=(true,false)`

  Enables incubating configuration on demand, where Gradle will attempt to configure only necessary projects.

  Default is `false`.

`org.gradle.console=(auto,plain,rich,verbose)`

  Customize console output coloring or verbosity.

  Default depends on how Gradle is invoked.

`org.gradle.continue=(true,false)`

  If enabled, continue task execution after a task failure, else stop task execution after a task failure.

  Default is `false`.

`org.gradle.continuous.quietperiod=(# of quiet period millis)`

  When using continuous build, Gradle will wait for the quiet period to pass before triggering another build. Any additional changes within this quiet period restart the quiet period countdown.

  Default is `250` milliseconds.

`org.gradle.daemon=(true,false)`

  When set to `true` the Gradle Daemon is used to run the build.

  Default is `true`.

`org.gradle.daemon.healthcheckinterval=(# of millis)`

  Gradle Daemon health will be checked after a specified number of milliseconds.

  Default is `10000;` (10 secs).

`org.gradle.daemon.idletimeout=(# of idle millis)`

  Gradle Daemon will terminate itself after a specified number of idle milliseconds.

  Default is `10800000` (3 hours).

`org.gradle.daemon.registry.base=(directory)`

  Specify a Daemon registry path where the daemon registry file (addresses of active daemons) and daemon log files reside.

  Default is `.` (local directory).

`org.gradle.debug=(true,false)`

  When set to `true`, Gradle will run the build with remote debugging enabled, listening on port 5005. Note that this is equivalent to adding `-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005` to the JVM command line and will suspend the virtual machine until a debugger is attached.

  Default is `false`.

`org.gradle.debug.host=(host address)`

  Specifies the host address to listen on or connect to when debug is enabled. In the server mode on Java 9 and above, passing `*` for the host will make the server listen on all network interfaces.

  Default is `null`; no host address is passed to JDWP (on Java 9 and above, the loopback address is used, while earlier versions listen on all interfaces).

`org.gradle.debug.port=(port number)`

  Specifies the port number to listen on when debug is enabled.

  Default is `5005`.

`org.gradle.debug.server=(true,false)`

  If set to `true` and debugging is enabled, Gradle will run the build with the socket-attach mode of the debugger. Otherwise, the socket-listen mode is used.

  Default is `true`.

`org.gradle.debug.suspend=(true,false)`

  When set to `true` and debugging is enabled, the JVM running Gradle will suspend until a debugger is attached.

  Default is `true`.

`org.gradle.dependency.verification=(strict,lenient,off)`

  Configures the dependency verification mode where in `strict` mode verification fails as early as possible, in order to avoid the use of compromised dependencies during the build.

  Default is `strict`.

`org.gradle.internal.instrumentation.agent=(true,false)`

  Enables the instrumentation Java agent for the daemon.

  Default is `true`.

`org.gradle.java.home=(path to JDK home)`

  Specifies the Java home for the Gradle build process. The value can be set to either a `jdk` or `jre` location; however, depending on what your build does, using a JDK is safer. This does not affect the version of Java used to launch the Gradle client VM.

  Default is derived from your environment (`JAVA_HOME` or the path to `java`) if the setting is unspecified.

`org.gradle.jvmargs=(JVM arguments)`

  Specifies the JVM arguments used for the Gradle Daemon. The setting is particularly useful for configuring JVM memory settings for build performance. This does not affect the JVM settings for the Gradle client VM.

  Default is `-Xmx512m "-XX:MaxMetaspaceSize=384m"`.

`org.gradle.logging.level=(quiet,warn,info,debug)`

  When set to quiet, warn, info, or debug, Gradle will use this log level. The values are not case-sensitive.

  Default is `lifecycle` level.

`org.gradle.logging.stacktrace=(internal,all,full)`

  Specifies whether stacktraces should be displayed as part of the build result upon an exception. See the `--stacktrace command-line option` for additional information.

  When set to `internal`, a stacktrace is present in the output only in case of internal exceptions.

  When set to `all` or `full`, a stacktrace is present in the output for all exceptions and build failures.

  Using `full` doesn’t truncate the stacktrace, which leads to a much more verbose output.

  Default is `internal`.

`org.gradle.parallel=(true,false)`

  When configured, Gradle will fork up to `org.gradle.workers.max` JVMs to execute projects in parallel.

  Default is `false`.

`org.gradle.priority=(low,normal)`

  Specifies the scheduling priority for the Gradle daemon and all processes launched by it.

  Default is `normal`.

`org.gradle.projectcachedir=(directory)`

  Specify the project-specific cache directory. Defaults to `.gradle` in the root project directory."

  Default is `.gradle`.

`org.gradle.unsafe.isolated-projects=(true,false)`

  Enables project isolation which enables configuration caching.

  Default is `false`.

`org.gradle.vfs.verbose=(true,false)`

  Configures verbose logging when watching the file system.

  Default is `false`.

`org.gradle.vfs.watch=(true,false)`

  Toggles watching the file system. When enabled, Gradle reuses information it collects about the file system between builds.

  Default is `true` on operating systems where Gradle supports this feature.

`org.gradle.vfs.watch.debug=(true,false)`

  Enables debug events emitted in `native-platform` to be shown. Events are only shown when `--debug` is enabled or when the daemon is between builds.

  Default is `false`.

`org.gradle.warning.mode=(all,fail,summary,none)`

  When set to `all`, `summary` or `none`, Gradle will use different warning type display.

  Default is `summary`.

`org.gradle.welcome=(never,once)`

  Controls whether Gradle should print a welcome message.

  If set to `never`, then the welcome message will be suppressed.

  If set to `once`, then the message is printed once for each new version of Gradle.

  Default is `once`.

`org.gradle.workers.max=(max # of worker processes)`

  When configured, Gradle will use a maximum of the given number of workers.

  Default is the number of CPU processors.

The following examples demonstrate how to use Gradle properties.

Example 1: Setting Gradle properties with a `gradle.properties` file:

gradle.properties

    gradlePropertiesProp=gradlePropertiesValue
    gradleProperties.with.dots=gradlePropertiesDottedValue

Example 2: Reading Gradle properties at configuration time:

settings.gradle.kts

    // Using the API, provides a lazy Provider<String>
    println(providers.gradleProperty("gradlePropertiesProp").get())

    // Using Kotlin delegated properties on `settings`
    val gradlePropertiesProp: String by settings
    println(gradlePropertiesProp)

build.gradle.kts

    // Using the API, provides a lazy Provider<String>
    println(providers.gradleProperty("gradlePropertiesProp").get())

    // Using Kotlin delegated properties on `project`
    val gradlePropertiesProp: String by project
    println(gradlePropertiesProp)

settings.gradle

    // Using the API, provides a lazy Provider<String>
    println providers.gradleProperty('gradlePropertiesProp').get()

    // Using Groovy dynamic names
    println gradlePropertiesProp
    println settings.gradlePropertiesProp

    // Using Groovy dynamic array notation on `settings`
    println settings['gradlePropertiesProp']

build.gradle

    // Using the API, provides a lazy Provider<String>
    println providers.gradleProperty('gradlePropertiesProp').get()

    // Using Groovy dynamic names
    println gradlePropertiesProp
    println project.gradlePropertiesProp

    // Using Groovy dynamic array notation on `project`
    println project['gradlePropertiesProp']

The Kotlin delegated properties are part of the Gradle Kotlin DSL. You need to explicitly specify the type as `String`. If you need to branch depending on the presence of the property, you can also use `String?` and check for `null`.

Note that if a Gradle property has a dot in its name, using the dynamic Groovy names is not possible. You have to use the API or the dynamic array notation instead.

Example 3: Reading Gradle properties for consumption at execution time:

build.gradle.kts

    tasks.register<PrintValue>("printProperty") {
        // Using the API, provides a lazy Provider<String> wired to a task input
        inputValue = providers.gradleProperty("gradlePropertiesProp")
    }

build.gradle

    tasks.register('printProperty', PrintValue) {
        // Using the API, provides a lazy Provider<String> wired to a task input
        inputValue = providers.gradleProperty('gradlePropertiesProp')
    }

Example 4: Setting Gradle properties from the command line:

    $ gradle -DgradlePropertiesProp=commandLineValue

Note that initialization scripts can’t read Gradle properties directly. The earliest Gradle properties can be read in initialization scripts is on `settingsEvaluated {}`:

Example 5: Reading Gradle properties from initialization scripts:

init.gradle.kts

    settingsEvaluated {
        // Using the API, provides a lazy Provider<String>
        println(providers.gradleProperty("gradlePropertiesProp").get())

        // Using Kotlin delegated properties on `settings`
        val gradlePropertiesProp: String by this
        println(gradlePropertiesProp)
    }

init.gradle

    settingsEvaluated { settings ->
        // Using the API, provides a lazy Provider<String>
        println settings.providers.gradleProperty('gradlePropertiesProp').get()

        // Using Groovy dynamic names
        println settings.gradlePropertiesProp

        // Using Groovy dynamic array notation on `settings`
        println settings['gradlePropertiesProp']
    }

Properties declared in a `gradle.properties` file present in a subproject directory are only available to that project and its children.

## 4. Environment variables

The following environment variables are available for the `gradle` command.

`GRADLE_HOME`

  Installation directory for Gradle.

  Can be used to specify a local Gradle version instead of using the wrapper.

  You can add `GRADLE_HOME/bin` to your `PATH` for specific applications and use-cases (such as testing an early release for Gradle).

`JAVA_OPTS`

  Used to pass JVM options and custom settings to the JVM.

`GRADLE_OPTS`

  Specifies JVM arguments to use when starting the Gradle client VM.

  The client VM only handles command line input/output, so it is rare that one would need to change its VM options.

  The actual build is run by the Gradle daemon, which is not affected by this environment variable.

`GRADLE_USER_HOME`

  Specifies the `GRADLE_USER_HOME` directory for Gradle to store its global configuration properties, initialization scripts, caches, log files and more.

  Defaults to `USER_HOME/.gradle` if not set.

`JAVA_HOME`

  Specifies the JDK installation directory to use for the client VM.

  This VM is also used for the daemon unless a different one is specified in a Gradle properties file with `org.gradle.java.home`.

The following examples demonstrate how to use environment variables.

Example 1: Reading environment variables at configuration time:

init.gradle.kts

    // Using the Java API
    println(System.getenv("ENVIRONMENTAL"))

settings.gradle.kts

    // Using the Java API
    println(System.getenv("ENVIRONMENTAL"))

    // Using the Gradle API, provides a lazy Provider<String>
    println(providers.environmentVariable("ENVIRONMENTAL").get())

build.gradle.kts

    // Using the Java API
    println(System.getenv("ENVIRONMENTAL"))

    // Using the Gradle API, provides a lazy Provider<String>
    println(providers.environmentVariable("ENVIRONMENTAL").get())

init.gradle

    // Using the Java API
    println System.getenv('ENVIRONMENTAL')

settings.gradle

    // Using the Java API
    println System.getenv('ENVIRONMENTAL')

    // Using the Gradle API, provides a lazy Provider<String>
    println providers.environmentVariable('ENVIRONMENTAL').get()

build.gradle

    // Using the Java API
    println System.getenv('ENVIRONMENTAL')

    // Using the Gradle API, provides a lazy Provider<String>
    println providers.environmentVariable('ENVIRONMENTAL').get()

Example 2: Reading environment variables for consumption at execution time:

build.gradle.kts

    tasks.register<PrintValue>("printValue") {
        // Using the Gradle API, provides a lazy Provider<String> wired to a task input
        inputValue = providers.environmentVariable("ENVIRONMENTAL")
    }

build.gradle

    tasks.register('printValue', PrintValue) {
        // Using the Gradle API, provides a lazy Provider<String> wired to a task input
        inputValue = providers.environmentVariable('ENVIRONMENTAL')
    }