Search code examples
gradleintellij-ideajavanixosnixpkgs

Gradle — The newly created daemon process has a different context than expected


I installed the OpenJDK via Nix in Ubuntu (Linux uplink 4.13.0-32-generic #35~16.04.1-Ubuntu SMP Thu Jan 25 10:13:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux).

gorre@uplink:~$ java -version
openjdk version "1.8.0_172"
OpenJDK Runtime Environment (build 1.8.0_172-02)
OpenJDK 64-Bit Server VM (build 25.172-b02, mixed mode)

gorre@uplink:~$ which java
/home/gorre/.nix-profile/bin/java

gorre@uplink:/nix/store/f9053w1lfrkhgqfpr6l82ssxmjpsni1j-openjdk-8u172b02$ ll
total 24K
dr-xr-xr-x 3 gorre 4.0K Dec 31  1969 share/
dr-xr-xr-x 2 gorre 4.0K Dec 31  1969 nix-support/
dr-xr-xr-x 3 gorre 4.0K Dec 31  1969 lib/
lrwxrwxrwx 1 gorre   80 Dec 31  1969 jre -> /nix/store/n7rh8v269qb1fs6314yq0wg7q8cajw0g-openjdk-8u172b02-jre/lib/openjdk/jre/
dr-xr-xr-x 2 gorre 4.0K Dec 31  1969 include/
lrwxrwxrwx 1 gorre   76 Dec 31  1969 bin -> /nix/store/f9053w1lfrkhgqfpr6l82ssxmjpsni1j-openjdk-8u172b02/lib/openjdk/bin/

Now when I try build/run a project that uses Gradle 4.4 within IntelliJ IDEA 2017.3.4 (Ultimate Edition) Build #IU-173.4548.28 I get this error:

The newly created daemon process has a different context than expected.
It won't be possible to reconnect to this daemon. Context mismatch: 
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=/nix/store/f9053w1lfrkhgqfpr6l82ssxmjpsni1j-openjdk-8u172b02,daemonRegistryDir=/home/gorre/.gradle/daemon,pid=12824,idleTimeout=null,daemonOpts=-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]
Actual: DefaultDaemonContext[uid=b813ba02-e4a6-4bfe-91b2-8ed32963f7cc,javaHome=/nix/store/f9053w1lfrkhgqfpr6l82ssxmjpsni1j-openjdk-8u172b02/lib/openjdk,daemonRegistryDir=/home/gorre/.gradle/daemon,pid=14245,idleTimeout=10800000,daemonOpts=-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]

I've searched here and there but the other answers/solutions don't work, not even specifying the Java home in gradle.properties (inside the project or in my user's home):

org.gradle.java.home = /nix/store/f9053w1lfrkhgqfpr6l82ssxmjpsni1j-openjdk-8u172b02

On the other hand, if I build/run the project on a terminal it works fine. Any clues?


UPDATE #1

This is my configuration for Gradle and the SDK in IntelliJ IDEA:

enter image description here

enter image description here


Solution

  • I figured this out, even though it was in front of my nose — I didn't read carefully the error message(s).

    Basically, the default Java home set by Nix was at: /nix/store/f9053w1lfrkhgqfpr6l82ssxmjpsni1j-openjdk-8u172b02/lib/openjdk and the one I manually set inside IntelliJ IDEA was at: /nix/store/f9053w1lfrkhgqfpr6l82ssxmjpsni1j-openjdk-8u172b02 (notice the missing ../lib/openjdk segment).

    After correcting that in IntelliJ IDEA everything worked fine. I didn't need anything additional and/or special.

    I hope this helps someone else in the future — or any other fast-reader Nix'ers.