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?
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.
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).
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 *)
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.
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.
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.
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
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.
Upgrading Gradle version 6.8.3 to 7.0 solved my problem. You can upgrade it:
It works with the Android Gradle plugin version 4.2.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With