Gradle : What is a Gradle Daemon ?

Points to Remember

  1. Gradle runs on JVM and several other dependencies.
  2. Gradle has to do boootstrap stuff whenever gradle is started.
  3. This startup process takes time and makes the build slower.

To overcome these points gradle daemon was introduced.

What is a Gradle Daemon ?

Gradle daemon is a long lived background background process that can be reused for building gradle projects faster. Gradle wrapper saves the time for starting a new gradle instance every time and saves time required for bootstrapping and initialization.Such bootstrap tasks include

  1. Initialization of JVM
  2. Cache Project information
  3. Cache files , tasks
  4. Project structures etc

Gradle daemon is configurable and can be switched on of off using gradle.properties in path <user-home>/.gradle/gradle.properties.

Also, gradle daemon should be used only for development environments and not for production environmnets. This is beacasue in production environments you want to build your projet independently since it is more reliable.

Check the status of Gradle Daemon

To check the status of the gradle deamon you can use the command

gradle --status

The above command gives the following output. (A Gradle version can only connect to daemons of the same version.)

   PID STATUS   INFO
  3461 IDLE     3.0
 31881 BUSY     3.0

Only Daemons for the current Gradle version are displayed.

How to stop a Gradle daemon

To stop all running gradle daemon processess you can run the following command.

gradle --stop

This will stop all the daemon processess that started with the same version of gradle that is used to execute the command.

States of a Gradle Daemon

A radle daemon can be in the following states.

  1. idle - this is a gradle state that is running but is not doing any execution. This gradle daemon can be used for running new builds.
  2. compatible - This is a gradle daemon that is compatible for running a gradle biuld.

Gradle build, firsts checks for an idle daemon with compatible configurations, if it exists, then the build is started using this daemon, if no such daemon exists then gradle will start a new gradle daemon for running the build.

No comments:

Powered by Blogger.