org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck:守护进程将在运行 3 小时后于构建结束时停止
org.gradle.launcher.daemon.server.DaemonExpirationPeriodicCheck: Daemon will be stopped at the end of the build after running for 3 hours
ID: cicd/gradle-daemon-stopped
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Gradle 8.5 | active | — | — | — |
| Gradle 8.7 | active | — | — | — |
| Gradle 7.6.3 | active | — | — | — |
根因分析
Gradle 的守护进程由于在 gradle.properties 中配置的空闲超时或最大年龄限制而自动终止,导致后续构建重启守护进程并丢失缓存状态。
English
Gradle's daemon process is automatically terminated due to idle timeout or maximum age limits configured in gradle.properties, causing subsequent builds to restart the daemon and lose cached state.
官方文档
https://docs.gradle.org/current/userguide/gradle_daemon.html解决方案
-
Increase daemon idle timeout in gradle.properties: `org.gradle.daemon.idletimeout=7200000` (2 hours)
-
Set daemon max age to a higher value: `org.gradle.daemon.registry.base.expiration=86400000` (24 hours) in gradle.properties
-
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
75% 失败
Disabling the daemon removes the caching benefit entirely, making builds significantly slower in CI environments.
-
Increase the daemon heap size with -Xmx to prevent memory-related stops
90% 失败
Heap size does not affect the idle timeout or age-based expiration; the daemon will still stop after the configured duration.
-
Restart the CI worker node to clear the daemon lock file
60% 失败
Restarting the node resets the daemon but does not address the underlying configuration causing the expiration.