Upgrade multiproject build from 1.12 to 2.3 fails with error: Could not dispatch a message to the daemon

We are using 64-bit Java 8 for this build. It works fine in 1.12, but any attempt to build a module or even initialize the gradle wrapper causes the daemon JVM to crash. There are no special entries in my gradle.properties other than

org.gradle.daemon = true
org.gradle.configureondemand = true

I do not get a crash when using a 32-bit Java 8 JVM. I do get a StackOverflowError. I’m not sure if this might help or not. The command line I’m running is

gradle :gx-rt:jar -a --debug --stacktrace

where gx-rt is one of our modules in the project. The debug output and the JVM crash log are available here. I’ll be happy to provide any additional information necessary.

Can you please try it on Java 7 and see if the issue persist? I would like to know if it’s a Java 8 specific problem.

Also to gather more data, could you please try on other release of JDK 8 (I can see that you’re using u31) like u25 or u40.

I’ve set my JAVA_HOME to a Java 7 installation. The build now fails during configuration phase, where it is trying to compile the main build.gradle script. We have a code signing plugin, and the failure indicates that it requires Java 8:

12:37:07.390 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
12:37:07.391 [ERROR] [org.gradle.BuildExceptionReporter]
12:37:07.391 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
12:37:07.391 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred configuring root project 'niagara'.
12:37:07.392 [ERROR] [org.gradle.BuildExceptionReporter] > Could not open no_buildscript class cache for build file 'D:\niagara\r40\niagara_dev_home\build.gradle' (C:\Users\E507094\.gradle\caches.3\scripts\build_3gpn179dw0iy30mqw9knocqq3\ProjectScript\no_buildscript).
12:37:07.392 [ERROR] [org.gradle.BuildExceptionReporter]
  > com/tridium/signing/DevFileSigningMgr : Unsupported major.minor version 52.0

I ran the build with the JRE 1.8.0_40

07:18:22.926 [INFO] [org.gradle.launcher.daemon.client.DefaultDaemonStarter] Starting daemon process: workingDir = C:\Users\E507094\.gradle\daemon.3, daemonArgs: [C:\Program Files\Java\jre1.8.0_40\bin\java.exe, -XX:MaxMetaspaceSize=1024m, -Dfile.encoding=windows-1252, -Duser.country=US, -Duser.language=en, -Duser.variant, -cp, C:\Users\E507094\.gradle\wrapper\dists\gradle-2.3-bin\a48v6zq5mdp1uyn9rwlj56945\gradle-2.3\lib\gradle-launcher-2.3.jar, org.gradle.launcher.daemon.bootstrap.GradleDaemon, 2.3, C:\Users\E507094\.gradle\daemon, 10800000, 3a8f83cf-29da-40b2-975e-b296ec3f2fb4, -XX:MaxMetaspaceSize=1024m, -Dfile.encoding=windows-1252, -Duser.country=US, -Duser.language=en, -Duser.variant]

I got the same daemon JVM crash result

07:18:41.435 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
07:18:41.435 [ERROR] [org.gradle.BuildExceptionReporter]
 07:18:41.435 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
07:18:41.436 [ERROR] [org.gradle.BuildExceptionReporter] Could not dispatch a message to the daemon.

I have also attempted to run the daemon in the foreground, then run the build script. I’d like to capture the process in Flight Recorder. The commands I run for the daemon are

>set GRADLE_OPTS=-XX:MaxMetaspaceSize=1024m -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=120s,filename=gradle_d.jfr
>gradle --daemon --foreground --debug -–stacktrace

This results in a daemon process that waits for a connection (pid = 26380)

15:03:52.160 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire exclusive lock on daemon addresses registry.
15:03:52.161 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired.
15:03:52.172 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
15:03:52.174 [DEBUG] [org.gradle.launcher.daemon.server.Daemon] requestStopOnIdleTimeout(10800000 MILLISECONDS) called on daemon
15:03:52.175 [DEBUG] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] Idle timeout: waiting for daemon to stop or be idle for 10800000ms
15:03:52.176 [DEBUG] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] Daemon is idle, sleeping until state change or idle timeout at Thu Mar 19 18:03:51 EDT 2015

The commands I run for the build are

>set GRADLE_OPTS=-XX:MaxMetaspaceSize=1024m -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=120s,filename=gradle.jfr
>gradlew :devkit-wb:clean -a --debug --stacktrace

The connection to the daemon is not made. It appears to detect the running daemon, but it does not “match the desired criteria”, and attempts to start another one (sorry, the markup syntax seems to mess up the output)

15:04:20.332 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
15:04:20.333 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired.
15:04:20.357 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
15:04:20.359 [DEBUG] [org.gradle.launcher.daemon.client.DefaultDaemonConnector] Found daemon DaemonInfo{pid=26380, address=[aec73fdd-1ee8-4254-b065-03188138baa1 port:64069, addresses:[/127.0.0.1, /0:0:0:0:0:0:0:1]], idle=true, context=DefaultDaemonContext[uid=814f3cc4-d93d-4ba5-87d4-b4c5e2906dab,javaHome=D:\niagara\r40\niagara_dev_home\jdk\jdk,daemonRegistryDir=C:\Users\E507094\.gradle\daemon,pid=26380,idleTimeout=10800000,daemonOpts=-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]} however its context does not match the desired criteria.
At least one daemon option is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=D:\niagara\r40\niagara_dev_home\jdk\jdk,daemonRegistryDir=C:\Users\E507094\.gradle\daemon,pid=25224,idleTimeout=null,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]
Actual: DefaultDaemonContext[uid=814f3cc4-d93d-4ba5-87d4-b4c5e2906dab,javaHome=D:\niagara\r40\niagara_dev_home\jdk\jdk,daemonRegistryDir=C:\Users\E507094\.gradle\daemon,pid=26380,idleTimeout=10800000,daemonOpts=-Dfile.encoding=windows-1252,-Duser.country=US,-Duser.language=en,-Duser.variant]
    Looking for a different daemon...
15:04:20.359 [INFO] [org.gradle.launcher.daemon.client.DefaultDaemonConnector] Starting Gradle daemon
15:04:20.388 [DEBUG] [org.gradle.launcher.daemon.client.DefaultDaemonStarter] Using daemon opts: [-XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=windows-1252, -Duser.country=US, -Duser.language=en, -Duser.variant]
15:04:20.390 [INFO] [org.gradle.launcher.daemon.client.DefaultDaemonStarter] Starting daemon process: workingDir = C:\Users\E507094\.gradle\daemon.3, daemonArgs: [D:\niagara\r40\niagara_dev_home\jdk\jdk\bin\java.exe, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=windows-1252, -Duser.country=US, -Duser.language=en, -Duser.variant, -cp, C:\Users\E507094\.gradle\wrapper\dists\gradle-2.3-bin\a48v6zq5mdp1uyn9rwlj56945\gradle-2.3\lib\gradle-launcher-2.3.jar, org.gradle.launcher.daemon.bootstrap.GradleDaemon, 2.3, C:\Users\E507094\.gradle\daemon, 10800000, 2811c940-f1ae-4130-874a-dbd90d3d224f, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=windows-1252, -Duser.country=US, -Duser.language=en, -Duser.variant]
15:04:20.413 [INFO] [org.gradle.process.internal.DefaultExecHandle] Starting process 'Gradle build daemon'. Working directory: C:\Users\E507094\.gradle\daemon.3 Command: D:\niagara\r40\niagara_dev_home\jdk\jdk\bin\java.exe -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\E507094\.gradle\wrapper\dists\gradle-2.3-bin\a48v6zq5mdp1uyn9rwlj56945\gradle-2.3\lib\gradle-launcher-2.3.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 2.3 C:\Users\E507094\.gradle\daemon 10800000 2811c940-f1ae-4130-874a-dbd90d3d224f -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant

There’s something odd about your environment that is causing the daemon compatibility test to fail. This is pretty hard to diagnose, and running in a debugger is the best option.

The code in question is here: https://github.com/gradle/gradle/blob/master/subprojects/launcher/src/main/java/org/gradle/launcher/…

You’ll need to:

1. Stop all daemon processes
2. Specify the JVM args needed to attach a debugger for the daemon
3. Start a debugging session from an IDE with the Gradle source code loaded up (you could open the Gradle project itself in your IDE)
4. Set a breakpoint at the line indicated by the link above
5. Step through and see exactly why it doesn’t think the contexts match.

It’s almost certainly in the ‘javaHomeMatches()’ method.

For step #2, the easiest way to do this is to add something like the following:

’’‘
org.gradle.jvmargs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005
’’'

to a ‘gradle.properties’ file in your root project. This will cause the daemon process to start and wait for a debugger, and not the client JVM. 

Please let me know what other steps you would like some detail on.

Actually, on closer inspection it’s telling us it doesn’t like the JVM args.

Do you have explicit memory settings in this environment?