Invalid JDK configuration found, while importing a project via Gradle

Intellij IdeaGradle

Intellij Idea Problem Overview


I have installed IntelliJ and I need to import a Gradle project.

I have build the gradle project using command prompt with the gradlew build command.

At the IntelliJ welcome page, I have proceeded with proper instructions, and when I choose "Finish". I get the following error:

> Invalid Gradle JDK configuration found. Open Gradle Settings JAVA_HOME ennvironment variable not set.

When I click on "Open Gradle Settings" it pop up with error of Not found with a path under IntelliJ directory in Program files and searching in jre/jre/bin/....etc.

Intellij Idea Solutions


Solution 1 - Intellij Idea

Deleting .gradle and .idea will likely solve the problem.

So:

  • Close the project
  • Go to the project dir and delete .gradle and .idea
  • Get back and re-open the project using the IDE

These two must be generated locally on your PC (Some content of .idea might be version controlled though) and not pulled from a remote or somewhere else (Also they should be in .gitignore).

In my case the reason was that these two folders were generated on another computer and I had opened a project with these two folders existing before.

Solution 2 - Intellij Idea

Just found the solution :

  • Create an empty Gradle project, then go to "Project Structure" and check the path to JDK (it should be valid, if it isn't you can add your own path).
  • Then build this empty project, wait and once done, close IntelliJ.
  • Relaunch it and try to import/open your Gradle project, now it should work.

Solution 3 - Intellij Idea

You don't need to create a new project to fix this. You can do it from the main window (Configure -> Project Defaults -> Project Structure):

enter image description here

Then, on SDKs, set the appropriate JDK home path:

enter image description here

If you are on a Mac, click on the button with 3 dots and select the folder /Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home.

I've found this here:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000266650-invalid-gradle-jdk-configuration-found

Solution 4 - Intellij Idea

Mac OS X Solution:

I had the same issue and fixed it by setting the JAVA_HOME environment variable using the command:

launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/

Refer to this answer on how to set environment variables in Mac OS X: Setting environment variables in OS X?

Solution 5 - Intellij Idea

Close the project Go to the project dir and delete

  • .gradle
  • .idea

Get back and re-open the project using the IDE

Solution 6 - Intellij Idea

To add to the previous responses, if you want to prevent this problem when cloning a repository in Git, you can simply remove .idea/misc.xml from your .gitignore file. This contains information about the project jar. For example:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>

Solution 7 - Intellij Idea

I recently had the same problem while importing a Gradle project. The trick was the remove the quotes from the JAVA_HOME variable. So instead of "C:\Program Files\Java\jdk1.8.0_66" my path now contains only the plain path C:\Program Files\Java\jdk1.8.0_66.

Solution 8 - Intellij Idea

For my case, I just restart the IDE and it works. It automatically download Gradle to suit the project version.

Solution 9 - Intellij Idea

I had the same problem on the fresh installed Windows OS. I did not have a JDK at all and forgot to check it invalid JDK configuration . By default, you can check the Project configuration. If it is empty NO_SDK_ProjectStructure try to download JDK from Oracle web site and configure your project structure

Solution 10 - Intellij Idea

I have faced same problem for tomcat 9 with my project based on Gradle. You can easily rectify the problem by configuring the application.properties file with the following code.

location - src/main/resources/application.properties

server.port = 9090

spring.security.user.name= admin

spring.security.user.password= password

Solution 11 - Intellij Idea

My issue was not addressed by the above solution, instead root cause was that I've imported settings from my old system and internal Intellij configuration was invalid because first jdk that it had in the list in jdk.table.xml pointed to a wrong path. To fix this you should find this file in the intellij config folder and then simply open it with an editor and remove whole block related to the bad jdk version.

Solution 12 - Intellij Idea

Close the project you are working on and then create another new project and build it and then close it and go back to your old project and it will work.

Solution 13 - Intellij Idea

Comment this code on gradle.properties, the Issue was gone.

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

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
QuestionSanujView Question on Stackoverflow
Solution 1 - Intellij IdeaMahdi-MalvView Answer on Stackoverflow
Solution 2 - Intellij IdeaEliottView Answer on Stackoverflow
Solution 3 - Intellij IdeaAlbert Vila CalvoView Answer on Stackoverflow
Solution 4 - Intellij IdeaPedro MadridView Answer on Stackoverflow
Solution 5 - Intellij Ideasadiq rashidView Answer on Stackoverflow
Solution 6 - Intellij IdeaandrewgazelkaView Answer on Stackoverflow
Solution 7 - Intellij IdeaJulian SieversView Answer on Stackoverflow
Solution 8 - Intellij IdeaMnTanProjectView Answer on Stackoverflow
Solution 9 - Intellij IdeaRoman DenisenkoView Answer on Stackoverflow
Solution 10 - Intellij IdeaSinghVatsal01View Answer on Stackoverflow
Solution 11 - Intellij IdeafuryView Answer on Stackoverflow
Solution 12 - Intellij IdeaHossam AliView Answer on Stackoverflow
Solution 13 - Intellij IdeaPravesh SinghView Answer on Stackoverflow