2

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

x80486
  • 5,131
  • 4
  • 32
  • 71
  • Make sure you have specified the `org.gradle.java.home` property in gradle.properties file file that is located in the same directory as build.gradle or in UDER_HOME/.gradle directory: https://stackoverflow.com/a/38212434/2000323 Try restarting the PC. Also check what is JAVA_HOME environment validate is set to. Try to set it to the JDK you are using for Gradle and remove `org.gradle.java.home` property re-login might be needed for changes to take effect). Issue also may be caused by symlink. Try removing the one for `jre` subdirectory. – Andrey Feb 22 '18 at 06:39
  • @Andrey I tried the `org.gradle.java.home` "trick" inside `gradle.properties` — it's in the question itself. On the other hand, (a) I did restart, (b) I don't have `JAVA_HOME` declared and/or set as environment variable, and (c) deleted the link for the `jre`...but nothing happens, still the same error. – x80486 Feb 22 '18 at 22:25

2 Answers2

3

Check Idea settings for Gradle daemon:

Build, Execution, Deployment -> Build Tools -> Gradle.

There is an option "Gradle JVM". Looks that Idea uses Java 9 or some other non-compatible JVM to run Gradle. Yoy should select your Java version from Nix.

gildor
  • 1,332
  • 10
  • 16
  • Yeah, I've checked that also. I'm actually using the right one there. I'll update the answer with two screen-shots for this one. – x80486 Feb 22 '18 at 02:33
2

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.

x80486
  • 5,131
  • 4
  • 32
  • 71