ChatGPT解决这个技术问题 Extra ChatGPT

Invalid JDK configuration found, while importing a project via Gradle

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.


M
Mahdi-Malv

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.


solve for me. however, i needed to import the project rather than open
That is awesome! Should be the selected answer.
Hey! Thanks in my case i have to delete those two folder before open project in Android Studio.
Creating an empty Gradle project did not fixed, This one worked for me.
Works for me. Note that I had Android Studio 3.6 and i did a Gradle SyncBuild there and it was working then some funky error stopped it talking about my IntelliJ was too old o something and I should try again after upgrading to Android Studio 4.2. So I did the upgrade reluctantly and then everytime i opened the folder it would give me this error. Doing what this answer said fixed it. Tho in 3.6 it was working fine with the Github/Remote .gradle and .idea folders
E
Eliott

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.


Yes it seems that when you run IntelliJ for the first time and try to run directly the "import gradle project" wizard, it fails to help you configuring the SDK. But when you run the "new gradle project" wizard, SDK is configured smoothly. Then you can cancel the wizard and go back to the "import gradle project" wizard.
I just went to New -> Gradle project. It showed a valid JDK and I closed out of the wizard at that point. I was then able to refresh my gradle project once it was done indexing.
This didn't work for me because my JDK was not set up correctly (it was pointing to an older build of Java 8 after I'd upgraded). @albert-vila-calvo's answer worked for me.
This worked for me! Invalidate cache/restart was not working. After creating an empty gradle project and going back to my springboot project resolved the issue. I also checked to see 'File -> Settings' 's 'Gradle' option is set as 'Gradle (default)' instead of 'Intellij IDEA'. Before facing this issue, I had upgraded gradle wrapper via terminal command 'gradle wrapper --gradle-version 6.8.2'
What a massive waste of time :'(
A
Albert Vila Calvo

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):

https://i.stack.imgur.com/oWhDb.png

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

https://i.stack.imgur.com/3LY4o.png

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


It's solved for me but bit a different, first steps... Open the project then open project structure... then follow this steps
C
Community

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?


This worked for me, cheers. Just had to restart for IntelliJ to pick up on the env var being there.
I must be the odd duck still using csh, but this worked for me on Mac OS X Sierra: setenv `JAVA_HOME /usr/libexec/java_home`. NOTE: java_home is a command so it is enclosed in backticks so it is evaluated.
s
sadiq rashid

Close the project Go to the project dir and delete

.gradle

.idea

Get back and re-open the project using the IDE


a
andrewgazelka

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>

J
Julian Sievers

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.


Removing quotes around the JAVA_HOME variable worked for me. Several other tools and utilities require the quotes due to the space in the middle, so I put the spaces back when done. Thanks!
M
MnTanProject

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


R
Roman Denisenko

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


S
SinghVatsal01

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

f
fury

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.


T
TT.

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.


P
Pravesh Singh

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

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


Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.