# org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck: Daemon will be stopped at the end of the build after running for X hours and not being used for Y hours

- **ID:** `cicd/gradle-daemon-stopped-after-build`
- **Domain:** cicd
- **Category:** system_error
- **Error Code:** `DAEMON_EXPIRATION`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Gradle daemon reaches its idle timeout (default 3 hours) or maximum age (default 24 hours) during a CI build, causing it to be stopped prematurely, which can lead to build failures if the daemon is needed for subsequent tasks.

## Workarounds

1. **Set org.gradle.daemon.idletimeout=7200000 in gradle.properties to increase idle timeout to 2 hours (value in milliseconds). Also set org.gradle.daemon.registrybase=/tmp/gradle-daemon to avoid PID file conflicts in CI.** (85% success)
   ```
   Set org.gradle.daemon.idletimeout=7200000 in gradle.properties to increase idle timeout to 2 hours (value in milliseconds). Also set org.gradle.daemon.registrybase=/tmp/gradle-daemon to avoid PID file conflicts in CI.
   ```
2. **Run Gradle with --no-daemon flag in CI scripts to avoid daemon lifecycle issues altogether: ./gradlew build --no-daemon** (90% success)
   ```
   Run Gradle with --no-daemon flag in CI scripts to avoid daemon lifecycle issues altogether: ./gradlew build --no-daemon
   ```

## Dead Ends

- **Set org.gradle.daemon=false in gradle.properties to disable daemon entirely** — Disabling daemon forces a new JVM for each build, increasing startup time and memory overhead, and may cause other race conditions in CI pipelines. (20% fail)
- **Increase max heap size for daemon (org.gradle.jvmargs=-Xmx4g) to avoid memory pressure** — Heap size does not affect idle timeout; the daemon is stopped based on time, not memory usage, so this fix is irrelevant. (80% fail)
