IntelliJ Gradle Plugin: The supplied javaHome seems to be invalid

JavaIntellij IdeaGradleIntellij 14

Java Problem Overview


Similar to:

However, I am trying to use my JAVA_HOME variable which is set to C:\Program Files\Java\jdk1.8.0_40

I do not understand why intellij is looking for the JDK inside of its install directory.

In intellij:

Executing external task 'bootRun'...
The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.1\jre\bin\java.exe
External task execution finished 'bootRun'.

C:\>java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

C:>env
...
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
...

Java Solutions


Solution 1 - Java

In my case the answers above didn't work. Here's what work for me: I needed to change Gradle JVM to point to the actual JDK: Image showing IntelliJ Settings window

Solution 2 - Java

IDEA comes in 2 versions: 32bit and 64bit.

Your JAVA_HOME is 64bit version of Java so you have to run 64bit version of the IDEA ...\IntelliJ\IntelliJ IDEA Community Edition 14.1.2\bin\idea64.exe.

Otherwise, you can provide 32bit JDK or tweak the behaviour with IDEA settings https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under

Solution 3 - Java

Try manually setting a JDK from File > Project Structure > Project > Project SDK, Then rebuild.

Solution 4 - Java

This can be fixed by setting the Project SDK in Module settings to a JDK (as opposed to the Module SDK (which shall be Android SDK)

Solution 5 - Java

I tried this and it worked for me flawlessly. go To SETTING-->SEARCH 'Gradle'---> and choose Gradle JVM and choose the option Use JAVA_HOME C:\ProgramFiles\Java\JDK\1.8 hope this helps someone.

Solution 6 - Java

I've solved this issue by putting gradle.properties file in the same dir as build.gradle with exact path to my JDK:

org.gradle.java.home = C:/Dev/JDK

Actually it is not a correct solution, probably it should be fixed in IDE, I see in IDEA logs something like (when I executing gradle task of already imported project):

INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/Dev/JDK

But when I going to import gradle module to the project I don't see such kind of message, probably IDEA passes link to bundled JRE which is actually not a JDK.

Solution 7 - Java

The problem lies in Intellij IDEA itself. If you go to Intellij installed directory, you will find a jre directory where it's searching for the above said java.exe. But the problem here is there is no bin directory here instead another jre directory available.So, solution is upfront. copy all the contents from inner jre directory and put it in outer jre directory.

Solution 8 - Java

UPDATE I believe this issue has been fixed as of 14.1.3

Related bug links:

That said, I was able to get by using @Sergii Pechenizkyi's answer; however, it seems like this problem has a few different solutions.

Solution 9 - Java

On OSX 10.12.x, Intellij v16.3, I had to go into:

  1. ~/Library/Preferences/IntelliJIdea2016.3
  2. Create a file called: idea.jdk
  3. Add the following to it: /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk (or whatever JDK you have installed

This was a fix I've had to do in v16 of Intellij found on jetbrains site. At one point I had to remove it, on the upgrade to 16.3 I had to add it back. https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under

Solution 10 - Java

I encountered the same problem for quite a while and no matter how many forums I looked at it just did not solve the problem.

Long story short, I found out my antivirus quarantined the java.exe file. So I advise you to open your antivirus and restore the Java.exe file then relaunch android studios.

Solution 11 - Java

Upgrading IntelliJ UE from v14.1.1 to 14.1.7 worked for me.

Solution 12 - Java

It is not working on the Mac as of 16.3. The SDK was set correctly in Project Settings and the Gradle dialog box no longer allows you to select the JDK. The only solution that worked was creating the gradle.properties file.

Solution 13 - Java

in IntelliJ 2018.1, I ran into this problem because my project SDK was set to Kotlin instead of a JDK. So, despite having a Kotlin project, it would only build if the SDK is a JDK.

Solution 14 - Java

After trying all above solution nothing worked for me. Then i looked whether the "Use project jdk" path for java is correct. To look it under File->settings->gradle-> gradle jvm I found that jdk got updated and gradle was using old jdk version. So, solution was to update Project jdk path for java in intellij. File->project structure->Platform setting->SDK, here update your right jdk path. thus the problem got solved for me.

Solution 15 - Java

In my case I delete ".gradle" folder and let android studio and react native download it again then problem get solved ... Notice: I'm using windows

Solution 16 - Java

in my case I had to delete cached java directory from Program Files/Common Files folder. This directory had previous java executa ble cached. Deleting this folder allowed system to recognize latest java executable

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric FrancisView Question on Stackoverflow
Solution 1 - JavahumazedView Answer on Stackoverflow
Solution 2 - JavaSergii PechenizkyiView Answer on Stackoverflow
Solution 3 - Javamushfek0001View Answer on Stackoverflow
Solution 4 - Javauser39950View Answer on Stackoverflow
Solution 5 - JavaMahesh JamdadeView Answer on Stackoverflow
Solution 6 - Java4ndrewView Answer on Stackoverflow
Solution 7 - JavaPradyumna SwainView Answer on Stackoverflow
Solution 8 - JavaEric FrancisView Answer on Stackoverflow
Solution 9 - JavadkochheiserView Answer on Stackoverflow
Solution 10 - JavaHaider MalikView Answer on Stackoverflow
Solution 11 - Javauser6718911View Answer on Stackoverflow
Solution 12 - Javauser7369766View Answer on Stackoverflow
Solution 13 - JavaKristopher NoronhaView Answer on Stackoverflow
Solution 14 - JavaAkanksha goreView Answer on Stackoverflow
Solution 15 - JavaUmamadView Answer on Stackoverflow
Solution 16 - JavaHiren VadaliaView Answer on Stackoverflow