46

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=/home/administrator/Downloads/idea-IU-145.1617.8/jre,daemonRegistryDir=/home/administrator/.gradle/daemon,pid=11963,idleTimeout=null,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=IN,-Duser.language=en,-Duser.variant] 

Actual:

DefaultDaemonContext[uid=4839fb8c-418b-4666-9a66-40a60133958a,javaHome=/usr/lib/jvm/java-8-openjdk-amd64,daemonRegistryDir=/home/administrator/.gradle/daemon,pid=15202,idleTimeout=60000,daemonOpts=-XX:MaxPermSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xmx1024m,-Dfile.encoding=UTF-8,-Duser.country=IN,-Duser.language=en,-Duser.variant]
2
  • Possible duplicate of IntelliJ Build Error Context Missmatch
    – Mormegil
    Commented Dec 1, 2016 at 13:10
  • Please ask an actual question or at least describe the problem rather than only quoting an error message. (The error message may of course be part of a question, but it shouldn't be the only part.)
    – das-g
    Commented Apr 10, 2019 at 10:20

10 Answers 10

70

Be sure to check and correct JDK version in these 3 places:

  1. Check Preferences -> Build,... -> Build Tools -> Gradle -> Gradle JVM: Gradle Preferences
  2. Check Project Structure -> Project Settings -> Project -> Project SDK:
    Project
  3. Check Project Structure -> Platform Settings -> SDKs: SDKs

Fixing gradle.properties is a dirty workaround. Better fix this at the IDE level.

4
  • 4
    I checked all of these and they were correct but it still is giving me the same error
    – jimboweb
    Commented Jan 6, 2019 at 16:07
  • 1
    Worked for me! In my case it appears that i've installed several times the same JDK version with sdkman. Checking that the same config appear in this 3 places really works!
    – andiblas
    Commented Jul 7, 2020 at 23:30
  • I disagree. Fixing this in gradle.properties is a purposeful fix. It has the advantage that it also works when executing Gradle from the CLI or from other applications. Instead the environment-specific configuration of your IDE should be kept to a minimum. Still I would recommend to configure it in your user specific properties file and not pollute the project's one with your personal settings. Commented Jan 24, 2021 at 16:04
  • 1
    For me, I was using java 11 in the IDEA GUI, but I had java 1.8 specified in the gradle.properties. Changing from 11 to 8 in the GUI fixed the error. Commented Oct 28, 2022 at 14:45
44

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
4
  • 8
    Your solution worked for me on OS X. I used org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home -- thanks.
    – Stevey
    Commented Mar 20, 2017 at 6:11
  • 3
    Yes I set org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home in ~/.gradle/gradle.properties (which did not previously exist on my Mac)
    – funkybro
    Commented Mar 9, 2018 at 8:57
  • create a file ~/.gradle/gradle.properties and put org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home as contents. Make sure use your own JAVA_HOME.
    – derek
    Commented Aug 8, 2019 at 20:31
  • I am using IntelliJ IDEA 2020.3.1 (Community Edition), I can not make it run using Java 11 (Azul), switching to Java 8 (Azul) based on Project SDK on Gradle settings, works.
    – mamaz
    Commented Jan 23, 2021 at 6:43
3

IntelliJ broke when I copied tools.jar to a jre/lib, attempting to make hot attach work.

3

Worked like magic.. have been struggling for 2 days now, just add:

org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home

in ~/.gradle/gradle.properties file.

1
  • To restate this for Windows., ~\.gradle\gradle.properties org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_192/jre
    – Andre
    Commented Aug 24, 2022 at 18:32
1

I ran into the same problem. This answer helped me.

Solution: In the bin folder of IntelliJ where you have it installed, run idea64.exe not idea.exe.

1

Fwiw - Had a similar thing after, and just reopening the project by picking the build.gradle file fixed it. (Also, done brew cask install java which placed jdk 10 in the default path)

1

For me this is solved when I selected the Project SDK option in gradle JVM. Even it was same when selected manually.

the preference window in intellij

0

The mentioned methods did not work for me. I am using Big Sur 11.4, M1 mac.

Remove Java like in the link below and reinstall it: https://actonnotes.wordpress.com/2020/11/22/how-to-remove-openjdk-version-15-on-apple-macos/

0

I struggled it whole day. For my case, it's not related to intellij. But as the repo uses an very outdated version of gradlew of 4.9. And it always complain a about a particular pid in the same error message. Which when I using jps or ps, it wasn't there. That drives me crazy. I reboot my machine many times, it still complains about the same pid. Later I found it cached the pid in the folder of: ~/.gradle/daemon/.... Such a dumb error message and logic. The finally I solved this problem but cleanup the whole ~/.gradle folder.

0
Java home is different.
Expecting: '/Users/******/.sdkman/candidates/java/current' but was: '/Users/*****/.sdkman/candidates/java/11.0.16.1-zulu/zulu-11.jdk/Contents/Home'.


Please configure the JDK to match the expected one.

for me me none of any of those suggestion worked. I am using mac with sdk man to manage the jdks. I checked gradle wrapper version in gradle/wrapper/gradle-wrapper.properties and updated from 6.8.2 to 6.9.3 and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.