# Gradle守护进程将在构建结束后停止，因为已运行X小时且未使用Y小时

- **ID:** `cicd/gradle-daemon-stopped-after-build`
- **领域:** cicd
- **类别:** system_error
- **错误码:** `DAEMON_EXPIRATION`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Gradle守护进程在CI构建期间达到空闲超时（默认3小时）或最大存活时间（默认24小时），导致被提前停止，如果后续任务需要该守护进程，可能导致构建失败。

## 解决方案

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.
   ```
2. ```
   Run Gradle with --no-daemon flag in CI scripts to avoid daemon lifecycle issues altogether: ./gradlew build --no-daemon
   ```

## 无效尝试

- **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% 失败率)
- **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% 失败率)
