How can I fix "unsupported class file major version 60" in IntelliJ IDEA?
Solution 1
TL;DR; You need to have the Java
version which is compatible with your Gradle
version, and configure Gradle to use exactly that version (not older Java, and not even newer version).
I fixed this problem by changing the Gradle JVM settings in IntelliJ settings:
-
In the Settings/Preferences dialog, go to Build, Execution, Deployment → Build Tools → Gradle.
-
Under the Gradle section, change the Gradle JVM option. Select a Gradle JVM which works for you.
See Resolve the Gradle JVM version for the existing project
Solution 2
For me, it was fixed by upgrading the Gradle version.
In the file under the directory gradle/wrapper/gradle-wrapper.properties
, just change the version number of Gradle. For example, if your Gradle version is 6.3
, change this:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
to:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
It is not available in File → Project Structure → Project for the project I was working with.
Solution 3
Upgrading Gradle version 6.8.3 to 7.0 solved my problem. You can upgrade it:
- Menu File → Project Structure → Project (on the left panel)
- Change to Gradle version 7.0
It works with the Android Gradle plugin version 4.2.0.
Solution 4
I fixed it too, the hard way:
Java
- Installed the latest Java JDK
- Fixed the Java path in the system environment variables by adding the JAVA_HOME variable (main Java folder without bin) and added %JAVA_HOME%\bin to the PATH environment variable
-
java -version
shows the correct version now
Gradle
- Installed Gradle from scratch using https://gradle.org/install/
- Fixed the Gradle path in the system environment variables by adding the GRADLE_HOME variable (main Gradle folder without bin) and added %GRADLE_HOME%\bin to the PATH environment variable
-
gradle -version
shows the correct version now incl. the correct JVM
IntelliJ IDEA settings
- Go to Settings → Build, Execution, Deployment → Build Tools → Gradle
- Edit Gradle user home (C:/Gradle/gradle-7.0.2)
- Use Gradle from: C:/Gradle/gradle-7.0.2
- Gradle JVM: JAVA_HOME version 16.0.1
Now it builds without error: Unsupported class file major version 60
Solution 5
For me, (in Flutter) the problem was that I was using Java JDK version 16, but version 16 is not supported for some packages.
So, I downgraded to JDK version 15.
On Windows, I did the following:
-
Close your current IDE / Terminal (do not skip this step).
-
Uninstall the current Java JDK and restart your computer.
-
Download and install Java JDK version 15 from here (you are required to create an account in order to download).
-
Update the
JAVA_HOME
Environment Variable.
Mason Wheeler
A lifelong programmer who's been coding in Delphi since its initial release and currently makes a living at it.
Updated on January 29, 2022Comments
-
Mason Wheeler over 2 years
I have a Gradle project in Ubuntu. It's written in Java 14. I have the Java 14 JDK installed. When I build it from the command line, everything works, but no one wants to use a command line! When I open it in IntelliJ IDEA, it throws an error:
* Where: Initialization script '/tmp/ijmapper.gradle` * What went wrong: Could not compile initialization script '/tmp/ijmapper.gradle`. > Startup failed: General error during semantic analysis: Unsupported class file major version 60.
followed by a long, unhelpful stack trace that says a lot about Groovy. (The project is not a Groovy project; it's a Java project.)
Major version 60 refers to Java 16, which this project is not using. I've already gone into Project Structure and made sure that it's set to use JDK version 14. But the name "ijmapper" suggests that this has something to do with IntelliJ specifically, and this is likely an IDE problem rather than a project problem.
The mapper file simply says:
if(!ext.has('mapPath')) ext.mapPath = { path -> path}
A simple polyfill, in other words.
What's going on here and how can I fix it?
-
phant0m about 3 yearsMentioning what setting worked for you and hat you had previously would help.
-
Ognjen almost 3 yearsjust got the issue on a kotlin tutorial github.com/kotlin-hands-on/intro-coroutines . Changing the Gradle JVM to 1.8 solved the issue
-
Ben Butterworth almost 3 yearsI downgraded from JDK 16 to JDK 15 to successfully build my app.
-
Tullochgorum almost 3 yearsDidn't work for me - a couple of builds went OK, then it barfed with the same message. Annoying thing is that the project wizard offered to install 16 for me, but it can't use it...
-
Amit Goswami over 2 yearsThis worked for me but i skipped GRADLE step
-
wondertalik over 2 yearsThanks. It works after updating Gradle Version to 7.0.2 and Android Gradle Plugin version from 4.1.0 to 7.0.1. In file android/build.grandle classpath changed to 'com.android.tools.build:gradle:7.0.1'. On my machine java 16.0.1, Flutter 2.2.3, Dart 2.13.4
-
Idan over 2 yearsYou saved my day 🥳
-
Tiny Sonhh over 2 yearsThis approach really saved my day! Yesterday, I switched to OJDK17 and worked very well. Don't know why today it says all errors and I have to set back to JDK15 and all good things back.
-
MohamedHarmoush over 2 yearsGradle (version> 7.3.2) now supports running on and building with Java 17.
-
MohamedHarmoush over 2 yearsGradle (version> 7.3.2) now supports running on and building with Java 17.
-
Rohinibabu over 2 yearsthank you for this answer! very helpful.
-
Johnny over 2 yearsI thinks Java has lots of changes after 1.8.x (Java 8).
-
yousoumar over 2 yearsYou saved my day !
-
ScottWelker almost 2 yearsThis answer enabled me to fix a command-line build failure. I wasn't actively using IntelliJ. I was seeing this error from the command-line. Since I had IntelliJ, I was able to use it to fix this Gradle issue. Nice! In my scenario I installed a side-by-side, earlier, proprietary JDK-17 but Gradle was configured to use the OpenJDK-18 found on my MacBook.