Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Gradle builds the environment


May 25, 2021 Gradle


Table of contents


Build an environment

Build your environment with a gradle.properties configuration

Gradle provides several options for easily configuring the Java processes that will be used to execute your build. W hen these options can be configured in your local environment through GRADLE_OPTS or JAVA_OPTS, they are more useful if certain settings such as JVM memory settings, Java home, daemon on/off, they can be versioned with your project in your version control system, so that the entire team can use a consistent environment. I n your build, setting up a consistent environment is as simple as putting these configurations into a gradle.properties file. These configurations will be applied in the following order (in case only the last one takes effect when there are configurations in multiple places):

  • Gradle.properties located in the project build directory.
  • gradle.properties located in the gradle user's home directory.
  • System properties, such as when -Dsome.property is used on the command line.

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

org.gradle.daemon
When set to true, the Gradle daemon runs the build. T his is our favorite property for local developers to build. T he developer's environment is optimized for speed and feedback, so we almost always run Gradle jobs using daemons. Because the CI environment is optimized for consistency and reliability, we do not run CI builds (i.e., long-running processes) through daemons.

org.gradle.java.home specifies the java home directory for the Gradle build process. T his value can be set to the location of jdk or jre, but depending on what you build, it is safer to select jdk. If this setting is not specified, a reasonable default value is used.

org.gradle.jvmargs specifies jvmargs for the daemon. T his setting is especially useful for adjusting memory settings. The default settings on the current memory are generous.

org.gradle.configureondemand
Enabling the new incubation mode allows Gradle to be selective when configuring projects. Only relevant projects are configured to be built more quickly in large multi-projects.

org.gradle.parallel
If this one is configured, Gradle will run in hatched parallel mode.

Forked java process

Many settings, such as the java version and maximum heap size, can be specified when starting a new JVM build process. T his means that after analyzing the various gradle.properties files, Gradle must start a separate JVM process to perform the build operation. W hen run through a daemon, the JVM with the correct parameters starts once and is re-used each time the daemon build is executed. When Gradle is not executed through a daemon, a new JVM must be started each time the build is executed, unless the JVM is started by a Gradle startup script and happens to have the same parameters.

Running an additional JVM at each build is very expensive, which is why we highly recommend using the Gradle daemon if you specify org.gradle.java.home or org.gradle.jvmargs. For more details, see Gradle Daemon.

Access the site through a proxy

Configuring an HTTP proxy server, such as for download dependencies, is done through standard JVM system properties. T hese properties can be set directly in the build script; for example, set the proxy host to System.setProperty ('http.proxyHost', 'www.somehost.org'). Alternatively, you can specify these properties in the root or in the Gradle.properties file in the Gradle home directory.

Configure the HTTP proxy server

gradle.properties

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost  

There are separate settings for HTTPS.

Configure the HTTPS proxy server

gradle.properties

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost   

We don't have a good overview of all possible proxy server settings. O ne place you can look at is a constant in a file for an Ant project. H ere is a link to the view of SVN. A nother place is the network property page of the JDK document. If someone knows a better overview, please email us to let us know.

NTLM authentication

If your proxy server requires NTLM authentication, you may need to provide a verification domain, along with a user name and password. There are two ways to provide a validation domain to an NTLM agent:

  • Set the http.proxyUser system property to a value such as domain/user name.
  • The validation domain is provided through the http.auth.ntlm.domain system properties.