Intellij Build Error Context Mismatch

IntelliJ Build Error Context Mismatch

I found this question while investigating a similar problem, and I solved mine, so maybe my experience will help.

Observations

My problem was similar to yours in that the Wanted context had the javaHome as the path to the JRE embedded in the IDEA install folder, and the Actual context had it as the first version of Java on my path. I found several similar error reports online but none had the IDEA embedded JRE as the Wanted version.

The Wanted Java version happened to be a system-wide install of the JRE, and not the JDK I had configured for the project, nor the value set for JAVA_HOME, which made me very suspicious (and confused). Re-ordering my path caused it to use yet another "unwanted" version of Java, so it was clearly using the path to choose what to run, but it wasn't clear why. I couldn't make IntelliJ's embedded JRE be first on my path, because I needed that to be the JDK for various reasons, so I needed another solution.

I also noticed (using Process Explorer, since I'm on Windows) that, in the failing case, IntelliJ launched a number of java.exe Gradle daemon processes, and that there were definitely no daemon processes running before I tried to start my build.

Solution

The cause turned out to be that I had defined a new configuration in the "Run/Debug Configurations" dialog and put the full path to the build.gradle file in the Gradle project: field, as follows. (I did this by clicking the ellipsis (...) button to the right of the field, but I could also have entered it directly.)

Run/Debug Configurations dialog showing Gradle project as an explicit path to a Gradle build file

However, what I should have done was follow the pattern in existing configurations, where the Gradle project: was specified as a "registered project", by clicking the "folder" icon to the right of the field, highlighted in green in the following image. In this case, the content of the field is just the project name, and is shown with subtly different background/foreground colours. (I accidentally discovered that right-clicking on this name will replace it with the path to the folder containing build.gradle, but if you cancel and start editing the configuration again, it will still appear as just the project name.)

Run/Debug Configurations dialog showing Gradle project as the name of a registered project

After making this change, the configuration built as expected, and I observed that only one java.exe was launched, using the same JDK path as when I ran tasks from the "Gradle" panel in the UI.

Intellij idea says Java Home is Different

Though I did not find the root cause where the different javaHomes have been taken from, at least I found a workaround that worked for me:

Try setting the following in your gradle.properties (either in $HOME/.gradle/ or in your project build dir):

org.gradle.java.home=/usr/lib/jvm/java-8-openjdk-amd64

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

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.

The newly created daemon process has a different context than expected. Java home is different. Change Java Home

I had the same problem, but luckily I found a solution.

You have to set the JAVA_PATH variable like this.

Step 1

Windows 7 – Right click My Computer and select Properties > Advanced

Windows 8 – Go to Control Panel > System > Advanced System Settings

Windows 10 – Search for Environment Variables then select Edit the system environment variables

Step 2

Click the Environment Variables button.

Step 3

Under System Variables, click New.

Step 4

In the Variable Name field, enter C:\android-studio\jre (The path to the Java version that comes with Android Studio)

Step 5

Click OK and Apply Changes as prompted

Step 6

Restart your computer and it will work.

Gradle Sync Failure in Fresh IntelliJ IDEA Install

The issue is likely caused by the incorrect Java home path specified for the JDK in IntelliJ IDEA. Make sure it points to the correct location like this:

/Users/rob/.sdkman/candidates/java/14.0.1-zulu/zulu-14.jdk/Contents/Home

On macOS /Contents/Home part of the path is significant.



Related Topics



Leave a reply



Submit