The Build Environment in Gradle

The Build Environment in Gradle

Configuring via gradle.properties in the build environment

Gradle has many ways to configure the process of java, which is used to execute a build. Also, for the configuration of the local environment via GRADLE_OPTS Or JAVA_OPTS  settings like JVM memory settings, Java home, a daemon on/off is very useful in a project. This helps the entire team to work with a consistent environment. Setting a consistent environment for a build is very easy, only we have to place these settings into the gradle.properties file. Below is the order for applying the configuration:

  1. Put Gradle.properties in the project build dir.
  2. Put Gradle.properties in the Gradle user home.
  3. Put system.properties on the command line.

Note: Gradle requires java JDK or JRE of version 7 or higher to run while setting these properties.

Following are the properties that can be used to configure the Gradle build environment:

1. org.gradle.daemon

When this property is set to true, the Gradle daemon uses it to run a build. From the version gradle 3.0, the daemon is enabled by default.

2. org.gradle.java.home

This property is used in java home for the Gradle build process. Values are set in jdk or jre location, depending on the build. A default setting is done when this setting is not specified.

3. org.gradle.jvmargs

The jvmargs is used for the daemon process. This setting is useful when pulling the memory setting.

4. org.gradle.configureondemand

This property is helpful during the configuration of a project. It is used for the fast build of large multi projects.

5. org.gradle.parallel

This property is used when multiple projects run parallelly.

6. org.gradle.workers.max

This property is configured when a Gradle uses the maximum number of workers. –max-workers is used for checking the details.

7. org.gradle.logging.level

This property is used during debugging in Gradle. These values are not case sensitive.

8. org.gradle.debug

When this property is set to true, the Gradle run the build with remote debugging. It is listed on port 5005.

9. org.gradle.daemon.performance.enable-monitoring

When this property is set to false, then the Gradle will not monitor the usage of running daemons.

10. org.gradle.caching

When this property is set to true, Gradle does not reuse the output from the previous builds.

Gradle properties and system properties

In Gradle, there are many ways to add properties in a build. In the command line, –D can be used for passing a system property to the JVM, which runs the Gradle.

Properties can also be added using properties files. The gradle.properties file is placed in the Gradle home directory or project directory. When there are multi-project builds, then gradle.properties file is placed in the subproject directory.

The properties which are set in gradle.properties file can be accessed using the object of the project.

Properties can also be added directly to the project object using –P in the command-line option.

One of the special features of Gradle is that it can also set project property when there is any specially named system or environment variable. This feature becomes very useful when you don’t have admin rights for a continuous integration server. Also, when you want to set property values that should not be easily visible for some security reasons. In this situation, –P option can be used, but system-level configuration files cannot be changed.