Build fails on daemon stopped unexpectedly even no daemon options

Hello,
I have a small problem and I can§t figure it out. My builds are failing on daemon stopped unexpectedly even though I have all possible no daemon options included. I have it in gradle.options in the same dir as my build.gradle is, I have it in gradle.properties in .gradle of my user and I am running the build with --no-daemon option and still the daemon runs… This is the log from the build:

[08:47:46][Step 2/2] Starting: bash /opt/gradle/gradle-4.6/bin/gradle --init-script /home/myuser/BuildAgent/plugins/gradle-runner/scripts/init.gradle --stacktrace --no-daemon --info -Dorg.gradle.daemon=false -b project/build.gradle clean build
[08:47:46][Step 2/2] in directory: /home/myuser/BuildAgent/work/e7ff0d752a333bde
[08:47:48][Step 2/2] Initialized native services in: /home/myuser/.gradle/native
[08:47:48][Step 2/2] To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/4.6/userguide/gradle_daemon.html.
[08:47:48][Step 2/2] Starting process 'Gradle build daemon'. Working directory: /home/myuser/.gradle/daemon/4.6 Command: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/bin/java -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Xmx3g -Dfile.encoding=UTF-8 -Djava.io.tmpdir=/home/myuser/BuildAgent/temp/buildTmp -Duser.country=US -Duser.language=en -Duser.variant -cp /opt/gradle/gradle-4.6/lib/gradle-launcher-4.6.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 4.6
[08:47:48][Step 2/2] Successfully started process 'Gradle build daemon'
[08:47:52][Step 2/2] An attempt to start the daemon took 3.463 secs.
[08:47:52][Step 2/2] The client will now receive all logging from the daemon (pid: 3535). The daemon log file: /home/myuser/.gradle/daemon/4.6/daemon-3535.out.log
[08:47:52][Step 2/2] Daemon will be stopped at the end of the build stopping after processing

And after 15 minutes it fails on the daemon stopping. Could anyone help please? BTW I am running in TeamCity (it doesn’t happen on local computer at all)

Thanks for all the answers.

Well, I found some info that it’s starting the daemon because of my java settings in gradle.properties, so I moved the settings to GRADLE_OPTS env var, but my builds are now failing for jvm out of memory error… Could anyone at least point me to any direction? I am running out of ideas. Thanks a lot

A short-lived daemon that stops at the end of the build vs. setting GRADLE_OPTS so that the initial JVM can run the build without forking another process probably didn’t change anything for you in this environment. The daemon stopped unexpectedly initially due to running out of memory. The only difference is that you can see the out of memory exception because it occurs in the same process. When the forked process died, it couldn’t communicate back to the initial process, so all it can say is that it disappeared unexpectedly.

It’s difficult for us to have any other ideas here as we don’t anything about your build, its memory usage, or the environment. Running a profiler is probably your best bet here to see what the build is doing.

I was running out of ideas, but Gradle voodoo in the form of rm -rf ~/.gradle/daemon solved the issue. The idea was borrowed from here: android - Gradle build daemon disappeared unexpectedly - Stack Overflow