# org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck：守护进程将在运行 3 小时后于构建结束时停止

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

## 根因

Gradle 的守护进程由于在 gradle.properties 中配置的空闲超时或最大年龄限制而自动终止，导致后续构建重启守护进程并丢失缓存状态。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Gradle 8.5 | active | — | — |
| Gradle 8.7 | active | — | — |
| Gradle 7.6.3 | active | — | — |

## 解决方案

1. ```
   Increase daemon idle timeout in gradle.properties: `org.gradle.daemon.idletimeout=7200000` (2 hours)
   ```
2. ```
   Set daemon max age to a higher value: `org.gradle.daemon.registry.base.expiration=86400000` (24 hours) in gradle.properties
   ```
3. ```
   Use the `--no-daemon` flag for short-lived CI builds to avoid daemon overhead, and rely on build cache instead: `gradle build --no-daemon --build-cache`
   ```

## 无效尝试

- **Set org.gradle.daemon=false in gradle.properties to disable daemon entirely** — Disabling the daemon removes the caching benefit entirely, making builds significantly slower in CI environments. (75% 失败率)
- **Increase the daemon heap size with -Xmx to prevent memory-related stops** — Heap size does not affect the idle timeout or age-based expiration; the daemon will still stop after the configured duration. (90% 失败率)
- **Restart the CI worker node to clear the daemon lock file** — Restarting the node resets the daemon but does not address the underlying configuration causing the expiration. (60% 失败率)
