Gradle daemon is never started from under Emacs

I run Gradle from Emacs, basically as (compile "cd ...; gradle ..."). Gradle always starts the daemon (or at least claims it does), but the daemon is never available next time I run it. However, if I execute exactly the same command from a normal shell, daemon is started and is available for next builds, even from under Emacs.

In other words, it looks like this:

  1. no daemon
  2. run from Emacs — slow startup, starts daemon
  3. run from Emacs — slow startup, again starts daemon
  4. run from Emacs — slow startup, again starts daemon

But, for comparison:

  1. no daemon
  2. run from terminal — slow startup, starts daemon
  3. run from Emacs — fast startup
  4. run from Emacs — fast startup
  5. run from Emacs — fast startup

Can you try running with --info?

My first suspicion is that Emacs is killing the process tree in the first case (Gradle forks the daemon, but Emacs kills both).

This sounds plausible (in which case it’s of course not a Gradle problem), I will look into what compilation mode is actually doing. As I understand, it shouldn’t kill anything and let the main process exit and daemon keep running, right?

I also ran it with --info, here is the output (actual build log is omitted as it is hardly interesting here).

cd ~/...; gradle --info ...
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
Starting daemon process: workingDir = /home/.../.gradle/daemon/2.5, daemonArgs: [/opt/jdk1.8.0_40/bin/java, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=UTF-8, -Duser.country=GB, -Duser.language=en, -Duser.variant, -cp, /home/.../.local/gradle-2.5/lib/gradle-launcher-2.5.jar, org.gradle.launcher.daemon.bootstrap.GradleDaemon, 2.5]
Starting process 'Gradle build daemon'. Working directory: /home/.../.gradle/daemon/2.5 Command: /opt/jdk1.8.0_40/bin/java -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8 -Duser.country=GB -Duser.language=en -Duser.variant -cp /home/.../.local/gradle-2.5/lib/gradle-launcher-2.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 2.5
Successfully started process 'Gradle build daemon'
An attempt to start the daemon took 0.481 secs.
Connected to daemon DaemonInfo{pid=20189, address=[62b44a55-b134-439e-86fc-f8a1566d8c9b port:62981, addresses:[/0:0:0:0:0:0:0:1%lo, /127.0.0.1]], idle=false, context=DefaultDaemonContext[uid=63642e25-06d4-4e0c-ae33-347d22b3b5b5,javaHome=/opt/jdk1.8.0_40,daemonRegistryDir=/home/.../.gradle/daemon,pid=20189,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=GB,-Duser.language=en,-Duser.variant]}. Dispatching request Build{id=306347ed-5b1e-4922-b17d-adbc3062323e.1, currentDir=/home/.../...}.
The client will now receive all logging from the daemon (pid: 20189). The daemon log file: /home/.../.gradle/daemon/2.5/daemon-20189.out.log
Starting build in new daemon [memory: 954.7 MB]
Executing build with daemon context: DefaultDaemonContext[uid=63642e25-06d4-4e0c-ae33-347d22b3b5b5,javaHome=/opt/jdk1.8.0_40,daemonRegistryDir=/home/.../.gradle/daemon,pid=20189,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=GB,-Duser.language=en,-Duser.variant]
Starting Build

[...]

BUILD SUCCESSFUL

Total time: 7.54 secs
Stopped 0 compiler daemon(s).
Received result Success[value=null] from daemon DaemonInfo{pid=20189, address=[62b44a55-b134-439e-86fc-f8a1566d8c9b port:62981, addresses:[/0:0:0:0:0:0:0:1%lo, /127.0.0.1]], idle=false, context=DefaultDaemonContext[uid=63642e25-06d4-4e0c-ae33-347d22b3b5b5,javaHome=/opt/jdk1.8.0_40,daemonRegistryDir=/home/.../.gradle/daemon,pid=20189,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=GB,-Duser.language=en,-Duser.variant]}.

Compilation finished at Mon Aug 10 09:43:04