Invalid JDK configuration found, while importing a project via Gradle - intellij-idea

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):
Then, on SDKs, set the appropriate JDK home path:
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

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?

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

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.

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>

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

I was getting:
Invalid JDK: /home/sz97/idea-IC-223.7571.182/jbr/bin/jlink is not a file!
Ensure JAVA_HOME or buildSettings.javaHome is set to JDK 15 or newer
As mentioned by Mahdi-Malv, delete .gradle & .idea folders from the project directory.
Then delete other SDKs from File > Project Structure > Platform Settings > SDKs keeping the only required one.
Finally change the SDK version from Project Structure > Project Settings > Project.
This may solve the problem.

Related

Intellij IDEA - JavaFX packager : access denied

I'm trying to generate an artifact of my JavaFX application using Intellij but for some reason I always end up having JavaFX packager throwing an access denied error on my output directory.
Generating a simple jar works fine though.
I'm using it on Windows 8.1 with Java 8.
I had the same problem. I kind of solved it:
by ticking the "Build on make" box in the Project Structur Dialog
starting a Run of my Java App in Intellij Idea
Now the executable jar magically appeared in my build folder. God knows why.
I had this problem and solved it by deleting the Artifact from IntellIJ, then deleting the "out/artifact" previously created folder where it tried to build my jar and finally re created an artifact from scratch. For no specific reason it now worked.
I have encountered the same problem recently. I checked the permissions of the directory and can read and write. Later I deleted the artifact and re-created a new one to solve the problem. I hope to help people who have encountered this problem.
I had this problem. I ran into it because When I added artifact with + button in Project Settings->Artifacts, I selected JAR artifact , and change JAR to JavaFx Application from type drop down box on right side pane. Later, I removed this artifact and pressed + button, then selected JavaFx Application from drop down list, then it was builded successfully. My JDK version is 8.
When I call JavaVXPacker from the command line I get the following:
C:\Users\Ingo>javafxpackager -help
javafxpackager.exe has been renamed javapackager.exe.
The original file may be removed in a future release in lieu of javapackager.
Please update your scripts.
...
...
So I guess IntelliJ has to update it's script to re-enable the feature???
(using Windows 10 and JDK Liberica 15+36)
Go to File > Project Structure
Click on Artifacts on the left panel.
Thereafter click on the plus icon to add a Jar From modules with dependencies…
A pop-up will be shown and there you would have to select for the startup class of your project.
Click on OK twice to save the changes.
Lastly go to Build > Build Artifacts... And select build action.
Now your jar will be generated in the out folder of your project.
For a more details guide, please refer to this post

Unable to make the module: related gradle configuration was not found. Please, re-import the Gradle project and try again

I use IntelliJ IDEA Ultimate 14 and Gradle 1.2. I manage the project from the console, but I need to debug some of the code from the IDE.
When I try to make the project, this error window appears. When I try to debug the project,
Error: Unable to make the module: idappcli, related Gradle configuration was not found.
Please, re-import the Gradle project and try again.
is written in the message window. How can I add the regular output paths to the project?
Try by opening the gradle task view and then click the refresh button. For me it solved the problem.
I also had a similar problem,
Go to : View -> Tool Windows -> Gradle.
Then press in Refresh Icon
This fixed the issue "Please, re-import the Gradle project and try again." for me (IntelliJ Ultimate 17.3.3):
(1) Detached Gradle project:
(2) Closed the project and (3) re-opened it via File > Open recent. IntelliJ will promt to import the now unlinked Gradle project. (4) Imported it and selected "Use auto-import" in the dialog.
I had the same problem with my Intellij IDEA version 2016.2 (Mac)
The solution was: In Intellij, Click on "View" then "Tool Windows" then "Gradle" then click on
I had to make sure the Use auto-import and the Use default gradle wrapper (recommended) were both checked.
File > Other Settings > Default Settings > Build, Execution, Deployment > Build Tools > Gradle
I faced the similar issue when i update my IntelliJ Idea.
To fix it i ran the below command in terminal and it fixed my problem.
gradle cleanIdea idea
For most people the refresh of Gradle that has already been suggested might solve the issue.
For the others I figured out, that deleting the .idea direcotory and reimporting the project might help.
It can be that your resources directory is not added to classpath when creating a project via Spring Initializr. So your application is never loading the application.properties file that you have configured.
To make a quick test if this is the case, add the following to your application.properties file:
server.port=8081
Now when running your application you should see in the spring boot console output something like this:
INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): **8081** (http) with context path ''
If your port is still default 8080 and not changed to 8081, your application.properties files is obviously not loading.
You can also check if your application runs with gradle bootRun from command line. Which most likely will be work.
Solution:
Close IntelliJ, then inside your project folder delete the ".idea" folder
Reimport your project to IntelliJ like following: "Import Project" -> "select ONLY your build.gradle file to import". (IntelliJ will automatically grab the rest)
build and run your application again
See official answer by IntelliJ Support:
IDEA-221673
This works for me:
Close the IntelliJ Idea
Delete 'gradle' and '.gradle' folders from the project root
Start IntelliJ Idea and import the project as gradle
In my case the root cause was a missing proxy configuration. Once I configured it properly I was able to Refresh gradle projects and it finally downloaded missing files and set up the project correctly.
File > Settings > Appearance & Behaviour > System Settings > HTTP proxy
then
View > Tool Windows > Gradle
and Synchronize button
I went into the IntelliJ Gradle preferences:
Menu: Preferences > Build, Execution, Deployment > Build Tools > Gradle
And under Project Level Settings, switched the radio button to "Use default gradle wrapper (recommended)"
Hit the make button, and was in business!
#user1339 I also had the same problem. Please, read this question Building war with Gradle, Debugging with IntelliJ IDEA. It'll be very helpful for you. And recommendation for the 'Make' task. As message said, I should try to re-import the Gradle project and try again. In my case this advice became very helpful.
I recommend to try to 'Build > Rebuild Project'.

How to define Gradle's home in IDEA?

I am trying to import a Gradle project into IntelliJ, and when I get to the Gradle Home textbox, it is not automatically populated, nor will typing in the path of Gradle Home result in a valid location - I have the GRADLE_USER_HOME environment variable set (to what I think is!) the correct path, and I have been able to successfully import this same project into Eclipse. Any suggestions?
You can write a simple gradle script to print your GRADLE_HOME directory.
task getHomeDir {
doLast {
println gradle.gradleHomeDir
}
}
and name it build.gradle.
Then run it with:
gradle getHomeDir
If you installed with homebrew, use brew info gradle to find the base path (i.e. /usr/local/Cellar/gradle/1.10/), and just append libexec.
The same task in Kotlin in case you use build.gradle.kts:
tasks.register("getHomeDir") {
println("Gradle home dir: ${gradle.gradleHomeDir}")
}
Installed on a Mac via Homebrew, the path
/usr/local/opt/gradle/libexec
is preferable to
/usr/local/Cellar/gradle/X.X/libexec
since the former will survive version upgrades.
If you installed gradle with homebrew, then the path is:
/usr/local/Cellar/gradle/X.X/libexec
Where X.X is the version of gradle (currently 2.1)
If you are using IntelliJ, just do the following.
Close the project
(re)Open the project
you will see "Import gradle project" message on the right bottom. click.
select "Use default gradle wrapper". not "Use local gradle distribution"
That's all.
This is what helped me solve the problem of not having Gradle home set for the IDEA when importing a Gradle project.
THREE OPTIONS -- (A) Default Wrapper (B) "gradle 'wrapper' task configuration" OR (C) "local gradle distribution" defined by jetbrains: https://www.jetbrains.com/help/idea/gradle-settings.html
A. Default Wrapper (recommended)
If you are able, select this recommended option. If it is grayed out, see option C, which should then set your default for all subsequent projects.
B. Gradle 'Wrapper' Task Configuration
If you want IDEA to define your gradle version for you from your build script
Set this option if you define your gradle build versions as a task within your actual gradle build.
Example below from jetbrains: https://www.jetbrains.com/help/idea/gradle-settings.html
(useful if you do not want to share gradle builds between projects)
C. Local Gradle Distribution
1. Run the following command to get gradle location:
brew info gradle (if gradle was installed with homebrew)
2. You are looking for something like this:
/usr/local/Cellar/gradle/4.8.1
3. Next, append 'libexec' to the gradle location you just found:
/usr/local/Cellar/gradle/4.8.1/libexec
This is because "libexec is to be used by other daemons and system utilities executed by other programs" (i.e. IDEA). Please see https://unix.stackexchange.com/questions/312146/what-is-the-purpose-of-usr-libexec
4. Finally, put that new path in the Gradle home input box if IDEA prompts you.
IDEA should now have allowed you to hit OK
C:\Users\<_username>\.gradle\wrapper\dists\gradle-<_version>-all\<_number_random_maybe>\gradle-<_version>
\Android studio\gradle didn't worked for me.
And "Default gradle wrapper" wasn't configured while importing (cloning) the project from bitbucket
If it causes problem to figure out the path, here is my path :
C:\Users\prabs\.gradle\wrapper\dists\gradle-5.4.1-all\3221gyojl5jsh0helicew7rwx\gradle-5.4.1
This is instruction for MAC only.
I had the same problem. I solved it by configuring $GRADLE_HOME in .bash_profile. Here's how you do it:
Open .bash_profile (usually it's located in the user’s home directory).
Add the following lines to update $PATH variable:
export GRADLE_HOME=/usr/local/opt/gradle/libexec
export PATH=$GRADLE_HOME/bin:$PATH
Save it.
Apply your changes by running
source .bash_profile
I wrote my own article with instruction in a case if somebody will encounter the same problem.
On a mac it should ideally be at : /Applications/Android Studio.app/Contents/gradle/gradle-2.14.1
(Replace the version string with the latest)
AFAIK it is GRADLE_HOME not GRADLE_USER_HOME (see gradle installation http://www.gradle.org/installation).
On the other hand I played a bit with Gradle support in Idea 13 Cardea and I think the gradle home is not automatically discover by Idea. If so you can file a issue in youtrack.
Also, if you use gradle 1.6+ you can use the Graldle support for setting the build and wrapper. I think idea automatically discover the wrapper based gradle project.
$ gradle setupBuild --type java-library
$ gradle wrapper
Note: Supported library types: basic, maven, java
Regards
If you're using MacPorts, the path is
/opt/local/share/java/gradle
I had to setup the Project SDK before selecting gradle path. Once that was set correctly, I had to choose "Use default gradle wrapper (recommended) in "Import Project from Gradle" dialog.
Still works if I remove gradle using brew:
$ brew remove gradle
This is where my gradle home is (Arch Linux):
/usr/share/java/gradle/
I had some weird errors where it could not find my class, I had to right click on my src folder (was red) to "Make Directory as" -> Source Folder Root
Click New -> Project from existing sources -> Import gradle project...
Then Idea recognized gradle automatically.
I couldn't get it to accept my Gradle JVM selection until I deleted a broken JDK
Th window below is from File -> Other Settings -> Structure For New Projects...
I had a red 1.8 JDK SDK entry here, once I deleted that Gradle JVM error below disappeared and I could move on to the next step
In case you are using Mac, most probably your gradle home should be /usr/local/gradle-2.0 for example.
In preference of IDEA search for gradle and set gradle home as given above.
It should work

intellij - java: Cannot find JDK '1.7' for module

I've just installed IntelliJ on Windows 8 (and 7). I then use the 'Java Hello World' Sample as my project.
I then selected the JDK that was installed (C:\Program Files\Java\jdk1.7.0_10). Project creates successfully and I can see all the classes associated with the project etc. When I "make the project" I get the following error:
Compilation completed with 1 error and 0 warnings in 2 sec
1 error
0 warnings
java: Cannot find JDK '1.7' for module 'TEST'
No matter what I do I cannot compile any Java code under Windows8/IntelliJ
I have tried the following:
Invalidating cache.
Switching to 32bit JDK instead of 64bit
Idea64.exe instead of idea.exe
Installing 1.6 incase it was a 1.7 issue??
Changed the JAVA_HOME to point to different versions (ie currently C:\Program Files\Java\jdk1.7.0_10)
I'm lost as to why this is happening.
project structure > project > choose correct jdk
or ctrl+alt+shift+s > project> choose correct jdk
also platform settings > SDK's >and make sure 1.7 is there.
Found the root of the problem. Turns out Windows 8 under parallels shares the same Desktop as OSX. This confused IntelliJ somehow and as a result it couldn't compile properly.
In parallels by removing the "Desktop" shared under Configure this then resolves the issue.
In case you want to still share the documents & desktop, the solution is to modify the idea.properties file (for instance, under C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.1\bin\idea.properties ), and change the following properties to point to different a location that is specific to the OS in which you are working:
idea.config.path=
idea.system.path=
idea.plugins.path=
idea.log.path=
I also copied the previous folder (on my computer it was under
\\psf\Home\.IntelliJIdea12
) to the new location to preserve all settings.
Update: I had the same problem after I installed IntelliJ Idea 13. I moved the .IntelliJIdea13 folder to c:\Users\costa from \\psf\Home, then I modified the C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.0\bin\idea.properties file:
idea.config.path=C:/Users/costa/.IntelliJIdea13/config
idea.system.path=C:/Users/costa/.IntelliJIdea13/system
idea.plugins.path=C:/Users/costa/.IntelliJIdea13/config/plugins
idea.log.path=C:/Users/costa/.IntelliJIdea13/system/log
I made the error while editing idea.properties to leave a whitespace at the end of my personally added idea.config.path=../.IdeaIC/config line.
This resulted exactly in the Cannot find JDK '...' for module error message.
I needed to "trim" the line manually, just deleted the whitespace, restarted IntelliJ and everything worked fine again.
I found this while scanning the idea.log file where I found java.io.FileNotFoundException: C:\Software\IntelliJ IDEA Community Edition 14.1.3\.IdeaIC\config \tasks\root.contexts.zip
In my case, Idea said "Failed to save settings" (probably due to a lot of projects being open. After that, it could not run tests with "Cannot find JDK '1.8' for module XXX" message. Idea restart solved the issue for me.
I believe this is an IntelliJ bug.
This isn't a fix, but you can work around this by going to Settings > Compiler, and disabling 'Use External Build'.
It seems that sometimes Intellij (or the user:-)) is getting confused when importing settings, especially if you change the paths where the jdk resides (for me it happened during a migration to a new Linux environment).
The only way I could correct this was to delete the user's settings folder.
In Linux :
I removed the folder (and subfolders): ~/.IntelliJIdea12/
Of course this would remove the saved settings, licenses e.t.c.

IntelliJ gives Fatal Error: Unable to find package java.lang in classpath or bootclasspath

When I try to make a simple module in IntelliJ it responds with:
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
Somehow the JDK language jars were removed from the classpath. All I had to do was reapply the JSDK home path.
Goto:
File -> Project Structure -> Platform Settings -> SDKs
Re-apply the JSDK home path.
Doing this added about 15 jars to the classpath. Apparently these are important for compiling.
File -> Project Structure -> Platform Settings -> SDKs, remove existing SDK and add it again.
Works for me in IntelliJ 2017.3.
This error happend to me after i've updated my JDK version to jdk1.8.0_161 -
But the project's sdk was still pointing to the old jdk 1.8.0_131
(Seems that updgrading java causing the previous version to be wiped).
Do this:
In the IntelliJ IDE go to File > Project Structure, from there:
Within Platform Settings > SDKs:
Make sure that the JDK Home path field is pointing to a valid JDK folder (add a new entry if needed e.g. jdk1.8.0_161).
Within Project Settings > Modules:
Make sure that the Module SDK is set to the same entry you picked in the Platform Settings > SDKs
Save & Build again.
This worked for me:
In Preferences Build Tools > Maven > Runner > Environment Variables set JAVA_HOME to your JDK home path.
Usually you want to use the same Java JDK you are using in IntelliJ. You can find that under Project Structure > Platform Settings > SDKs under JDK home path.
e.g. /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
In Intellij Community 2019.1, this is what I did to solve the issue
Project Structure > Platform Settings > SDKs
Removed all existing SDKs listed ( I had multiple SDK listed there)
Add the required SDK only and Apply
File > Project Structure
JDK home path : PASTE_THE_JDK_LOCATION (Like here in the "Project Structure screen shot"
Build Again
Cheers :)
After following this answer,
I learned that %LOCALAPPDATA%/IDEA/config/options/jdk.table.xml contained incorrect entries. Fixing the JDK table fixed the problem.