Why is IntelliJ IDEA unable to determine java version? - java

I'm rather new to IntelliJ IDEA and Grails in general. I just started a new Project, selected my project JDK (11.0.1) and Gradle distribution (4.10.2). Whenever I try to run the project, I get this error:
Error initializing classpath: Could not determine java version from
'11.0.1'. java.lang.IllegalArgumentException: Could not determine java
version from '11.0.1'. at
org.gradle.api.JavaVersion.toVersion(JavaVersion.java:68) at
org.gradle.api.JavaVersion.current(JavaVersion.java:78) at
org.gradle.internal.jvm.UnsupportedJavaRuntimeException.assertUsingVersion(UnsupportedJavaRuntimeException.java:29)
at
org.gradle.tooling.internal.consumer.ConnectorServices.checkJavaVersion(ConnectorServices.java:66)
at
org.gradle.tooling.internal.consumer.ConnectorServices.close(ConnectorServices.java:53)
at
org.gradle.tooling.internal.consumer.DefaultGradleConnector.close(DefaultGradleConnector.java:57)
at
org.grails.cli.gradle.cache.CachedGradleOperation.call(CachedGradleOperation.groovy:78)
at
org.grails.cli.GrailsCli.populateContextLoader(GrailsCli.groovy:525)
at org.grails.cli.GrailsCli.initializeProfile(GrailsCli.groovy:508)
at
org.grails.cli.GrailsCli.initializeApplication(GrailsCli.groovy:306)
at org.grails.cli.GrailsCli.execute(GrailsCli.groovy:269) at
org.grails.cli.GrailsCli.main(GrailsCli.groovy:159)
All other discussions of the problem I found suggested changing the Gradle distribution, which I already did. I would be so happy if anybody could help me out here.
Cheers!

May be your java configuration is not correct. If not correct follow this steps.
Goto File-> Project Structure.
Change SDK
Or gradle version is not matching jdk 11 then skip this answer.

Besides the issue with Gradle above, if you're trying to run a Grails project I don't think you can do that with JDK higher than version 8.
Even the latest Grails (3.3.8 as of this writing) is still based on SpringBoot 1.5 which does not support newer JDK, I don't know if there's a special trick to make it work.

I had to delete the .gradle directory and restart Intellij.

Related

InteliJ Mac Catalina: Java 11 or newer is required to run the IDE

Hello yesterday I updated my IntelliJ ide to the latest version (2020.3.2). The problem is that it's not starting anymore. When I try to open it, I get this error message:
I have two JDKs, 8 and 12
It seems like InteliJ does some kind of lookup by alphabetical order because when I rename my jdk 8 to other name that goes after the "jdk-12..." it actually works
The problem is that have to rename the folders and then return the original names to make my projects work, is there a way to avoid this renaming? Thanks a lot
This IntelliJ IDEA version requires Java 11 to run.
You override default bundled JetBrains Runtime with Java 8.
The solution is to remove this override. It's either idea.jdk file in the configuration directory or an environment variable as described in this document:
~/Library/Application Support/JetBrains/IntelliJIdea2020.3/idea.jdk
Note that JDK used to run IntelliJ IDEA itself is not related to the JDK that you are using to build and run your own projects. These two can be different.
I bumped into this issue with my PyCharm. In that case, pycharm.jdk was the one we need to remove.
~/Library/Application Support/JetBrains/PyCharm2020.3$ mv pycharm.jdk /tmp
Hope it helps someone came here by google.

Intellij build after gradle refresh fails on wrong java version

I am using Gradle with intellij.
I refresh Gradle and then I rebuild my project.
I get the following
Notice the first line - Using:javac 1.8.0_65
But I get the error that I should use -source7 or higher.
I also set the following at the settings
(With all of the inner modules are set to project sdk (1.8))
But I still can't rebuild or compile without this error.
Any suggestions?
(obviously i deleted all my classes and jars and then Gradle refreshed and rebuild project)
Same issue; got it solved with the following:
Go to: File / Settings / Build,Execution,Deployment / Build Tools /
Gradle / Gradle JVM
Then choose: Use JAVA_HOME
As of your second screen, make sure that all your modules are using the project default SDK, like in the screen below. The module setting may somehow be set to point older java version.
I had this problem while trying to build Android Studio. I kept getting
Tools need to be compiled with Java 1.8, you are using Java 11
Everything in the Intellij global and "Project Structure" settings was set to Java 1.8 so I couldn't figure out what was going on. For whatever reason, what ended up working was going to Build, Execution, Deployment > Build > Gradle and selecting the Amazon corretto version of Java 1.8 as installed by sdkman. This is baffling since I'd already tried selecting two other options for Gradle JVM that said 1.8 and both of those still resulted in the same error message as a result of Java 11 being used.
I finally resolved this issue for myself. I'm on Windows and it turns out the order in which the JDKs are listed in the Windows environment variable matter, and overrode what IDEA had set.
Although my project has JDK11 listed everywhere, JDK17 was still being used. I was able to finally resolve this issue by moving their ordering to list JDK11 first.
before I swapped the env var order
after (hurray!)

STS - Gradle - Java Home is different

Today I turn on my laptop and STS shows me this error, and I dont have any idea, Why STS is raising this.
My java home is :
and my gradle project is using java 1.7.
Maybe you can help me to solve this problem.
Thank you.
This can be related to having multiple jdk installs and can be fixed by renaming the other jdk folders, however the true problem here may be caused by a symlink in /jdk1.8.0_71/jre/lib/tools.jar pointing to jdk/1.8.0_71/lib/tools.jar. Remove the symlink and see if Gradle works.

The type java.util.Comparator cannot be resolved

The type java.util.Comparator cannot be resolved. It is indirectly referenced from required .class files
I recently installed Java 8. While executing an application, I got above mentioned error can you please help me.
I am using:
Java - jdk1.8.0_51
Tomcat - apache-tomcat-5.5.26
Assuming you are using some IDE, like Eclipse. When you are using jdk 1.8 with IDE, you need to update your IDE to support version 1.8.
It does not matter you are using new jdk's feature or not, but compiler has to load new JRE files in order to compile your project.
If you are using IntelliJ, go to:
File/Settings/Build, Execution, Deployment/Compiler/Java Compiler
and make sure "Use compiler" and "Project bytecode version" have the right configuration.
I had this same error and tried many things to fix it, but finally worked was remarkably simple: It turns that I was simply using an older version of Eclipse that did not support a "Compliance Level" setting of Java that was as high as my JRE. I merely upgraded to a newer version and the problem went away.
From what I understand about "Compliance Level", it's the version of Java that your program is supposed to work on. That much I found out from reading stuff on the net. But what the other solutions did not mention is that your IDE has to be able to be set to a level as high as your JRE. In my case, I was using JRE 1.8, but the highest compliance level my older IDE supported was 1.6.
IMO, this situation should have been flagged as an error by Eclipse. But as it was, I wasted two nights trying to figure this out.
Your project build path could be referring to a jre instead of JDK.
Go to your build path. (In eclipse right click and choose build path).
Go to your libraries and replace the jre with the jdk.
pom.xml version is 1.6?
If this is the way,you would replace jdk1.8 with jdk1.6 ,and environment variable into jdk1.6。
Same strange problem occurred. It turned out that wrong jdk version was in JAVA_HOME
There you are I had the same issue but moment I saw your question i got it fixed. problem is you are not using old version since there is mismatch of referencing with new version. this error will come.
Work around:
1. Change your java version to old.(In my case I had to change to 7)
2. Update each libray and jar file compatible to java 8 that way it will refer java not class file
Here is the image of environment variable in my problem
check if build path is set to run with JDK. It is important point that JKD is software development kit while JRE is a runtime env. Advice who had this problem see the different between JDK, JRE and JVM. https://www.guru99.com/difference-between-jdk-jre-jvm.html

bad version in class file

When I use certain jars in one of the connector projects i write for lombardi in TeamWorks eclipse i get a bad class version exception...
any ideas how this might be resolved..
Regards,
Adhir
You will get this error if you are using (say) Java 1.5 and you are using a JAR compiled with Java 1.6.
The easiest way to resolve is to upgrade your version of Java to the one used by the JAR.
Try to compile/recompile all your stuff with the same compiler.
Typically this happens when you have something compiled with a higher version and
you try to run it with an older one.
This problem can also be caused by an expired (365-day) Android certificate referenced by Eclipse.
See "Debug certificate expired" error in Eclipse Android plugins for details.
This is a result of running code compiled with a compiler version that is greater than the version of java you are using to run it. IE Code compiled with 1.6 and you are running it with 1.5. See this post to determine what version it was compiled with.
how-can-i-find-the-target-java-version-for-a-compiled-class
the easiest fix is to run it with the most recent JVM.
Root Cause for this error is that: jars including in your project is complied from other version of java and you are compiling your project from other version of java simply upgrading version of java will resolve this problem.
I also faced the same problem.

Categories