skip to content

Is the Gradle Daemon enabled by default, and how do you control it via the `org.gradle.daemon` flag?

level: juniorimportance: should knowfreq 35%

answer

  1. on by default since Gradle 3.0
  2. org.gradle.daemon=true|false in gradle.properties
  3. --daemon / --no-daemon override per run
  4. CLI flag beats the property
  5. project vs ~/.gradle/gradle.properties

basics

~10 s

Yes — the daemon has been on by default since Gradle 3.0. You control it with the org.gradle.daemon property in gradle.properties (true/false), or per-build with the --daemon / --no-daemon flags.

solid answer

~40 s

The Gradle Daemon is **enabled by default** (since Gradle 3.0), so every normal `gradle` / `./gradlew` invocation already uses one — you don't have to start it explicitly. You control it at two levels: - **Persistently**, via the `org.gradle.daemon` property in `gradle.properties` (project-level `./gradle.properties`, or user-level `~/.gradle/gradle.properties`): ```properties org.gradle.daemon=false # disable for this project / user ``` - **Per-invocation**, with the command-line flags `--daemon` and `--no-daemon`, which override the property for that single run. Precedence: the **command-line flag wins** over the `gradle.properties` value for that build. A common setup is to leave the daemon on for development (the default) and pass `--no-daemon` only in single-use CI runs. There's no need to manually 'turn on' a daemon — the client starts one automatically when enabled.

code

toml · 6 lines
toml
# gradle.properties (project root or ~/.gradle/)
org.gradle.daemon=true     # default; set false to disable persistently

# Override for a single run on the command line:
#   ./gradlew build --no-daemon
#   ./gradlew build --daemon

go deeper

for a junior

Know it's on by default and that org.gradle.daemon plus --no-daemon control it.

for a middle

Explain the two config locations and that the CLI flag overrides the property.

for a senior

Discuss standardizing daemon/JVM settings via ~/.gradle for a team and the per-run override pattern for CI.

for a principal

Define org-wide gradle.properties conventions (committed project defaults vs user-home overrides) so daemon behavior is consistent and reusable across the fleet.

## Default: on Since **Gradle 3.0**, the daemon is **enabled by default**. Practically, that means your everyday `./gradlew build` already runs through a daemon without any configuration. (In much older Gradle you had to opt in; that's history now.) ## The `org.gradle.daemon` property The persistent switch is a property, read from `gradle.properties`: ```properties # enable (this is the default, so usually unnecessary) org.gradle.daemon=true # disable persistently org.gradle.daemon=false ``` `gradle.properties` can live in two main places, both honored: - **Project root** — `./gradle.properties`, scoped to that project. - **Gradle user home** — `~/.gradle/gradle.properties`, applied to all builds for that user. ## Command-line flags For a single run you can override the property: ```bash ./gradlew build --no-daemon # force off for this run ./gradlew build --daemon # force on for this run ``` ## Precedence For a given invocation: 1. A **command-line flag** (`--daemon` / `--no-daemon`) takes top priority. 2. Otherwise the **`org.gradle.daemon`** value from `gradle.properties` applies. 3. Otherwise the **default** (enabled) applies. So `org.gradle.daemon=true` in your file plus `--no-daemon` on the command line ⇒ this build runs without a daemon. ## Typical configuration ```properties # ~/.gradle/gradle.properties — sensible developer defaults org.gradle.daemon=true org.gradle.jvmargs=-Xmx2g ``` Leave it on for development; reach for `--no-daemon` only where a warm JVM is wasted (e.g. a one-shot CI container). You almost never need to *start* a daemon by hand — enabling it is enough; the client spawns one on demand.

  • If gradle.properties has org.gradle.daemon=true but you pass --no-daemon, what happens?
    That build runs without a daemon — the command-line flag overrides the property for that single invocation. The property still applies to other runs.
  • Where can org.gradle.daemon be set?
    In gradle.properties, either at the project root (per-project) or in Gradle user home ~/.gradle/gradle.properties (all builds for that user). User-home is handy for machine-wide developer defaults.

saying these in an interview costs you the question

  • Saying you must manually start a daemon before building — the client starts one automatically when enabled.
  • Claiming the daemon is off by default in modern Gradle — it's been on since 3.0.

context