# org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck：守护进程将在构建结束时因 JVM 内存不足而停止

- **ID:** `cicd/gradle-daemon-out-of-memory`
- **领域:** cicd
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

Gradle 守护进程超出了分配的 JVM 堆内存，导致守护进程过期，并可能因 OutOfMemoryError 或 GC 开销限制而导致构建失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Gradle 8.2 | active | — | — |
| JDK 17 | active | — | — |
| Gradle 7.6 | active | — | — |

## 解决方案

1. ```
   Increase the Gradle daemon heap in gradle.properties: org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m. Adjust values based on runner memory (e.g., 4GB runner: -Xmx3072m).
   ```
2. ```
   Disable the daemon for memory-constrained CI by passing --no-daemon to Gradle, but this increases build time.
   ```

## 无效尝试

- **** — Restarting the daemon without increasing memory will cause the same failure on the next build. (50% 失败率)
- **** — Setting -Xmx too high on a CI runner with limited RAM can cause the OS to OOM-kill the process. (30% 失败率)
