org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck: 守护进程将在构建结束后停止,因为它运行了3小时5分钟,且构建环境已达到最大堆大小限制
org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck: Daemon will be stopped at the end of the build after running for 3 hours and 5 minutes because the build environment has reached its maximum heap size limit
ID: cicd/gradle-daemon-stopped-memory
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Gradle 7.6 | active | — | — | — |
| Gradle 8.2 | active | — | — | — |
| Gradle 8.5 | active | — | — | — |
根因分析
Gradle 守护进程因 JVM 内存分配不足而耗尽堆内存,通常是由于 CI 运行器 RAM 有限或未为大项目调整 Gradle JVM 参数。
English
Gradle daemon runs out of heap memory due to insufficient JVM memory allocation for the build, typically when the CI runner has limited RAM or the Gradle JVM args are not tuned for large projects.
官方文档
https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties解决方案
-
Set JVM args in gradle.properties: org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m. Then restart daemon: ./gradlew --stop && ./gradlew build
-
Reduce parallel test execution: In build.gradle, set 'tasks.withType(Test).configureEach { maxParallelForks = 1 }' and 'forkEvery = 50' to limit memory per fork.
无效尝试
常见但无效的做法:
-
60% 失败
Increasing Gradle daemon heap via GRADLE_OPTS without checking CI runner limits often still fails because the runner's total memory is capped.
-
70% 失败
Disabling the daemon with --no-daemon may cause slower builds but doesn't fix OOM if the build itself is memory-hungry in the JVM process.
-
80% 失败
Adding more parallel forks with maxParallelForks can increase memory pressure, making OOM worse.