Gradle build daemon disappeared unexpectedly

Hi Gradle peeps,

Trying to build iOS fat framework on Kotlin Multiplatform but it is failing with error:

* Exception is:
org.gradle.launcher.daemon.client.DaemonDisappearedException: Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
        at org.gradle.launcher.daemon.client.DaemonClient.handleDaemonDisappearance(DaemonClient.java:250)
        at org.gradle.launcher.daemon.client.DaemonClient.monitorBuild(DaemonClient.java:223)
        at org.gradle.launcher.daemon.client.DaemonClient.executeBuild(DaemonClient.java:185)
        at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:148)
        at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:99)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:56)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:212)
        ....
        at org.gradle.launcher.Main.doAction(Main.java:35)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:50)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:31)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:35)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:108)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)

Gradle properties ~/.gradle/gradle.properties:

org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home
org.gradle.jvmargs=-XX:MaxMetaspaceSize=2g -Xmx6g -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.daemon=true
org.gradle.parallel=true
kotlin.compiler.execution.strategy=in-process

Gradle daemon gets killed/disappears at 2g - 3g memory usage.

Environment: Java 8, 11 and 17, Kotlin 1.4.32, Gradle 6.5.1, macOS Big Sur

Any ideas what is wrong? It used to build fine. Any help is much appreciated.

You can have a look at $GRADLE_USER_HOME/daemon/6.5.1 for the daemon log file whether there is some additional information included.

If it is not, on Linux I’d suspect the OOM killer which works independently of -Xmx and kills processes if system RAM is getting low and the OS is considering some process to be too memory hungry. Maybe there is something similar on macOS and you can find something in the system logs?

In my case what stopped the issue was to go into the daemon dir for my gradle wrapper version ($GRADLE_USER_HOME/daemon/7.4) and select all the files there, then remove them. Then I tried to sync my project again and it worked.

Seems like Gradle keeps logs files for too long maybe?