Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "unsupported class file major version 60" in IntelliJ?

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?

like image 897
Mason Wheeler Avatar asked Apr 13 '21 17:04

Mason Wheeler


People also ask

How to fix Unsupported class file major version 60?

To Solve General error during semantic analysis: Unsupported class file major version 60 Error Simplest And the easiest solution is to change the Gradle JVM. here is a quick guide to change the Gradle JVM. In the Settings/Preferences dialog Ctrl+Alt+S, go to Build, Execution, Deployment | Build Tools | Gradle.

What is unsupported class file major version 61?

class file major version 61 means that the class file you are trying to load has been compiled by Java 17 or higher and can only by used by Java 17+. The Android toolchain only support only classes compiled for Java 11 (if the project is properly configured).

How to fix unsupported class file major version 60 in Gradle?

Go to Settings → Build, Execution, Deployment → Build Tools → Gradle Now it builds without error: Unsupported class file major version 60 In my case ( Manjaro Linux), the issue was that there is a known bug with OpenJDK 16 and Gradle. (See: * " Unsupported class file major version 60" Using toolchain with Java 16 #16766 *)

Why do I get unsupported class file major version 60 error?

If you have a project that uses JDK 14 with gradle 6.3 and you upgrade the JDK to version 16 then you get the error Unsupported class file major version 60 because gradle 6.3 is not compatible with Java 16. So the root cause is independent from your IDE.

What is JDK version 60 for IntelliJ?

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.

Is it possible to use Java 16 in IntelliJ?

On the Github page under requirements it does state that you need to use Java 16 in order for it to work properly. I have the Java 16 JDK installed on my computer and tried setting the source and target to 16 and it still doesn't work. In IntelliJ, I also set it to use the 16 JDK. You have to set the java version in your pom.


3 Answers

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, DeploymentBuild ToolsGradle.

  • Under the Gradle section, change the Gradle JVM option. Select a Gradle JVM which works for you.

    Enter image description here

See Resolve the Gradle JVM version for the existing project

like image 67
Yu Jinyan Avatar answered Oct 21 '22 02:10

Yu Jinyan


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 FileProject StructureProject for the project I was working with.

like image 63
John Lehmann Avatar answered Oct 21 '22 00:10

John Lehmann


Upgrading Gradle version 6.8.3 to 7.0 solved my problem. You can upgrade it:

  • Menu FileProject StructureProject (on the left panel)
  • Change to Gradle version 7.0

It works with the Android Gradle plugin version 4.2.0.

like image 19
Emirhan Soylu Avatar answered Oct 21 '22 00:10

Emirhan Soylu