# Gradle 构建守护进程意外停止。守护进程将在构建结束后因内存不足而停止。

- **ID:** `cicd/gradle-daemon-stopped-build-limit`
- **领域:** cicd
- **类别:** runtime_error
- **错误码:** `GRADLE_DAEMON_OOM`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Gradle 守护进程超过了配置的最大堆内存大小，导致被 JVM 或操作系统终止，通常是由于 CI 运行器中的内存分配不足。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Gradle 7.x | active | — | — |
| Gradle 8.x | active | — | — |
| Gradle 8.5 | active | — | — |

## 解决方案

1. ```
   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.
   ```
3. ```
   In CI, set the GRADLE_OPTS environment variable: `export GRADLE_OPTS="-Xmx512m -XX:+UseG1GC"` before running the build
   ```

## 无效尝试

- **** — 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% 失败率)
- **** — This avoids the daemon but causes slower builds and may not resolve the underlying memory pressure if the build itself requires more memory. (30% 失败率)
