# Gradle build daemon stopped unexpectedly. The daemon will be stopped at the end of the build after running out of memory.

- **ID:** `cicd/gradle-daemon-stopped-build-limit`
- **Domain:** cicd
- **Category:** runtime_error
- **Error Code:** `GRADLE_DAEMON_OOM`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The Gradle daemon exceeded the configured maximum heap size, causing it to be killed by the JVM or the OS, typically due to insufficient memory allocation in CI runners.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Gradle 7.x | active | — | — |
| Gradle 8.x | active | — | — |
| Gradle 8.5 | active | — | — |

## Workarounds

1. **Set a lower maximum heap size and enable parallel garbage collection: add `org.gradle.jvmargs=-Xmx1024m -XX:+UseParallelGC` to gradle.properties** (75% success)
   ```
   Set a lower maximum heap size and enable parallel garbage collection: add `org.gradle.jvmargs=-Xmx1024m -XX:+UseParallelGC` to gradle.properties
   ```
2. **Reduce build parallelism by setting `org.gradle.workers.max=2` in gradle.properties, which limits concurrent tasks and memory usage.** (85% success)
   ```
   Reduce build parallelism by setting `org.gradle.workers.max=2` in gradle.properties, which limits concurrent tasks and memory usage.
   ```
3. **In CI, set the GRADLE_OPTS environment variable: `export GRADLE_OPTS="-Xmx512m -XX:+UseG1GC"` before running the build** (80% success)
   ```
   In CI, set the GRADLE_OPTS environment variable: `export GRADLE_OPTS="-Xmx512m -XX:+UseG1GC"` before running the build
   ```

## Dead Ends

- **** — If the CI runner has a hard memory limit (e.g., 4 GB), the daemon may still be killed if total memory usage exceeds that limit. (40% fail)
- **** — This avoids the daemon but causes slower builds and may not resolve the underlying memory pressure if the build itself requires more memory. (30% fail)
