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.
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.
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.
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:
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?
setenv `JAVA_HOME /usr/libexec/java_home`
. NOTE: java_home
is a command so it is enclosed in backticks so it is evaluated.
Close the project Go to the project dir and delete
.gradle
.idea
Get back and re-open the project using the IDE
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>
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
.
For my case, I just restart the IDE and it works. It automatically download Gradle to suit the project version.
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
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
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.
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.
Comment this code on gradle.properties, the Issue was gone.
#org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home
Success story sharing