i'm trying to run a project from Spring Initializr and I am getting the error java.lang.UnsupportedClassVersionError
when I try to run the Main. The complete error is java.lang.UnsupportedClassVersionError: has been compiled by a more recent version of the Java Runtime (class file version 62.0), this version of the Java Runtime only recognizes class file versions up to 55.0
. The gradle is set to jvmTarget = 18
but aparrently when I put it to 11
it seem to fix the problem. I want to know why when I downgrade the version the program work.
Asked
Active
Viewed 566 times
0

OdisBy
- 15
- 4
-
Seems you execute programs with JDK version lower than version used for build. – y.bedrov Aug 08 '22 at 08:52
-
The problem is than 18 > 11 but 11 works and 18 not. – OdisBy Aug 08 '22 at 08:54
-
which version of gradle are you using ? `https://docs.gradle.org/current/userguide/compatibility.html` – Quentin Genet Aug 08 '22 at 08:56
-
I'm using gradle version 7.5. Which is compatible with java 18. – OdisBy Aug 08 '22 at 09:02
-
which JDK are you using in your IDE ? In your global settings ? And in your project structure ? – Quentin Genet Aug 08 '22 at 09:12
2 Answers
1
This error shows that you use older JRE version to run than to build. Your setup in gradle, you have to check what is your runtime version.
It seems you use IntelliJ. Go to File > Project Structure > Project > SDK - check if you have the Java 18 set here. You can also check in Run Configuration if there is proper JVM set.
Check also the JAVA_HOME env variable and set this variable to point to your recent JDK.

dey
- 3,022
- 1
- 15
- 25
-
I had 3 directories, 1.8 18 and jbr-11, I change the path of jbr-11 to the path of jdk 18 and it fix the problem! But thank you so much! – OdisBy Aug 08 '22 at 10:41
0
I finally fixed the problem, I had to change the jetbrains runtime in project structure to the jdk 18 path. Aparently it fix the problem.

OdisBy
- 15
- 4