Gradle Daemon

Gradle Daemon

Gradle runs on the JVM (Java Virtual Machine) and uses many supporting libraries, and requires more time for initialization. This results in a slow startup sometimes. The solution to this problem is Gradle Daemon. The Gradle daemon is a background process that can execute builds very quickly. Using this, we can avoid expensive bootstrapping process and cache, by keeping the data about the project into the memory. We can run Gradle builds with Daemon. To use the Gradle daemon, a configuration is done and then, everything is handled by the Gradle.

Gradle daemon is a long live process. Using this, we can avoid the cost of JVM Startup for every build. Also, the information about project structure, files, tasks and memory can be gathered. The reason behind this is that it improves the build speed by reusing the computation from previous builds, and also the build time is reduced by 15%-75% on the subsequent builds. From Gradle 3.0, the Gradle daemon is enabled by default. If a CI build environment is run, which does not reuse any processes, then the daemon will automatically decrease the performance, or it may be disabled.

Running Daemon Status

To get the running Daemon of a project, gradle–status is used.

Example:

gradle –status

Output:

E:\project2>gradle --status
   PID STATUS   INFO
 23236 IDLE     5.5.1
 17604 STOPPED  (by user or operating system) 

Only Daemons for the current Gradle version are displayed. See https://docs.gradle.org/5.5.1/userguide/gradle_daemon.html#sec:status

In the above example, only given Gradle version can be connected to daemons of the same version. This means the status will only show Daemons for the version of Gradle, which is being invoked, and not for any other versions.

Disabling the Daemon

By default, the Gradle daemon is enabled and it is always recommended to enable it. There are many ways to disable the daemon, the most common way is to add the below-given line.

org.gradle.daemon=false

in the file «USER_HOME»/.gradle/gradle.propertiesin where «USER_HOME» is the home directory.

 Depending on the platform, below can be the home directories:

  • Windows Vista & 7+: C:\Users\<Username>
  • Mac OS X: /Users/ <Username>
  • Linux: /home/<Username>

If the file does not exist, then create it using any text editor.

Stopping an existing Daemon

The Gradle daemon is a background process. There is no problem with the build-up of the Gradle process on the machine due to the daemon. All the daemons monitor memory usage and compare it with the system memory, and it stops itself when the available system memory is low, or it is ideal. And to explicitly stop the daemon process gradle -- stop is used.

The above command will terminate all the daemon process, which were started with the same Gradle version, that was used for executing the command.

When JDK (Java Development Kit) is installed in the system, then it is very easy to verify whether the daemon is stopped.