192

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
  • How are you running it in Intellij? Doesn't intellij print the exact command at the top of the terminal panel? It usually does. Take that and compare it to what you were running manually – Michael Apr 13 '21 at 17:06
  • 3
    Does https://stackoverflow.com/a/66879514/104891 help? – CrazyCoder Apr 13 '21 at 17:12
  • 3
    @CrazyCoder I was today years old when I learned that Gradle has its own JDK setting rather than respecting the one you set for the project. Thanks, I'd have never thought to look that up! – Mason Wheeler Apr 13 '21 at 17:22
  • 2
    And you will be tomorrow years old, when you learn, that IntelliJ will sometimes just forget about this setting and switches from PROJECT_JDK to something, that is around. – cfrick Apr 13 '21 at 17:25
  • check your system java, despite my settings in AS my JAVA_HOME wasnt being set and i had to explicitly set it to the version used in the environment-setup https://stackoverflow.com/questions/21964709/how-to-set-or-change-the-default-java-jdk-version-on-macos – raddrick Jul 07 '21 at 06:06
  • Try jdk-15 for gradle config – MinhajulAnwar Aug 02 '21 at 09:51
  • For anyone in the future thinking "This couldn't be my issue, I just created the project and gradle supports my version of java!" just like I thought, think again. [Check your gradle version](https://stackoverflow.com/questions/30054911/how-to-determine-the-version-of-gradle). As of November 2021, the libjdx project creator uses gradle 6.0, and I'm guessing it's not the only framework which does this. – import huh Nov 28 '21 at 20:27

17 Answers17

180

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

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Yu Jinyan
  • 2,051
  • 1
  • 10
  • 9
  • 23
    Mentioning what setting worked for you and hat you had previously would help. – phant0m Apr 30 '21 at 19:39
  • 5
    just got the issue on a kotlin tutorial https://github.com/kotlin-hands-on/intro-coroutines . Changing the Gradle JVM to 1.8 solved the issue – vincent May 27 '21 at 18:51
  • 2
    I downgraded from JDK 16 to JDK 15 to successfully build my app. – Ben Butterworth Jul 12 '21 at 08:19
  • 2
    Didn'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... – Tullochgorum Jul 17 '21 at 18:55
  • This 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. – Tiny Sonhh Oct 14 '21 at 09:31
  • I thinks Java has lots of changes after 1.8.x (Java 8). – Johnny Jan 18 '22 at 02:38
  • This 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. – ScottWelker Jun 21 '22 at 18:18
  • Thanks, this solution has to be the proper one. – Istorn Oct 12 '22 at 07:36
  • Additional observation: some modules won't sync with JDK 19, but are syncing with JDK 11 BUT when I sync them with 11 and change back to 19 then its still working. – Lukk17s Oct 27 '22 at 13:44
  • For Unix Command line, you could also use the alias https://github.com/YunaBraska/gradle-java-fix This alias just sets the right java version for your gradle project – Yuna Braska Jan 13 '23 at 07:36
76

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John Lehmann
  • 896
  • 6
  • 5
  • 7
    Gradle (version> 7.3.2) now supports running on and building with Java 17. – MohamedHarmoush Dec 19 '21 at 10:58
  • 1
    This compatibility chart helped me to pick the correct version https://docs.gradle.org/current/userguide/compatibility.html#java – tamj0rd2 May 05 '23 at 18:17
  • 1
    This worked for me, since I was not able to change the Gradle JVM settings through IntelliJ's Settings/Preferences -> Build,Execution, Deployment -> Build Tools -> Gradle (The Gradle section just did not exist in my case). You can find the matching JDK depending on your Gradle version and vice versa on this page: https://docs.gradle.org/current/userguide/compatibility.html – Kristian Heitkamp May 20 '23 at 14:47
  • So simple, so effective! I had 7.2 set and Java 19. Changed according to that compatibility chart to 7.6 and started right up. – MiB Jun 12 '23 at 15:38
21

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Emirhan Soylu
  • 681
  • 6
  • 12
  • Thanks. 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 – wondertalik Aug 24 '21 at 09:51
  • 1
    Gradle (version> 7.3.2) now supports running on and building with Java 17. – MohamedHarmoush Dec 19 '21 at 10:59
11

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:

  1. Close your current IDE / Terminal (do not skip this step).

  2. Uninstall the current Java JDK and restart your computer.

  3. Download and install Java JDK version 15 from here (you are required to create an account in order to download).

  4. Update the JAVA_HOME Environment Variable.

MendelG
  • 14,885
  • 4
  • 25
  • 52
10

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*)

The solution was to point Java to openJdk-11 with the following command:

sudo archlinux-java set java-11-openjdk

Make sure that this JDK is installed. On Arch Linux and Manjaro you can check it with:

archlinux-java status

After switching to OpenJDK 11 everything works again like expected.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
suther
  • 12,600
  • 4
  • 62
  • 99
9

I fixed it too, the hard way:

Java

  1. Installed the latest Java JDK
  2. 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
  3. java -version shows the correct version now

Gradle

  1. Installed Gradle from scratch using https://gradle.org/install/
  2. 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
  3. gradle -version shows the correct version now incl. the correct JVM

IntelliJ IDEA settings

  1. Go to SettingsBuild, Execution, DeploymentBuild ToolsGradle
  2. Edit Gradle user home (C:/Gradle/gradle-7.0.2)
  3. Use Gradle from: C:/Gradle/gradle-7.0.2
  4. Gradle JVM: JAVA_HOME version 16.0.1

Now it builds without error: Unsupported class file major version 60

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
8

I faced the same issue, but with Android Studio. It seems like JDK 17 is not compatible with Gradle 7.0.2 as the others mentioned that.

I fixed this problem by changing the Gradle JDK settings in Android Studio settings:

In menu FileSettingsBuild, Execution, DeploymentBuild ToolsGradle.

In the Gradle section, change the Gradle JVM option to another JDK (example: JDK11).

Later Gradle versions (version higher than 7.3.2) support running on and building with Java 17.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MohamedHarmoush
  • 1,033
  • 11
  • 17
8

To fix "Unsupported class file major version 63" we need to update gradle to v7.6:

gradle-wrapper.properties

distributionUrl=https://services.gradle.org/distributions/gradle-7.6-all.zip

Yauheni Prakapenka
  • 1,056
  • 11
  • 10
6

The correct version of Java is needed, here's a list:

Java SE 19 = 63,
Java SE 18 = 62,
Java SE 17 = 61,
Java SE 16 = 60, 
Java SE 15 = 59,
Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94
5

I ran into the same issue. It seems like JDK 17 is not compatible with Gradle 7.0.2.

Download JDK 16, drop it _somewhere_ (close to other JDK's folders or whatever)

Next, update: Project StructureSDK LocationGradle SettingsGradle JDK to match that _somewhere_

At the end, don't forget to Sync Project with Gradle files.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cody Tookode
  • 862
  • 12
  • 22
5

Changing, as people mentioned above, the page with the correct compatibility: Compatibility Matrix

In my case it was 7.3, because I was using JDK 17 and Java 8 worked for me!

// gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
Jeff Tian
  • 5,210
  • 3
  • 51
  • 71
Lucia Clifford
  • 136
  • 1
  • 6
5

12.31.2022 UPDATE

To everyone who has this problem, and have not found solution yet. First of all, you have to check for the compatibility of your Java version, and first Gradle version to support it, in: Compatibility Matrix.

Then you have to change the distributionUrl in: android/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
Rokas Rudzianskas
  • 582
  • 1
  • 7
  • 10
2

My project is using Java 16 and Maven to build a Spring Boot application. I got the same error and was able to resolve it with these steps:

  1. Navigate to IntelliJ IDEA → Preferences...Build, Execution, DeploymentCompiler → *Java Compiler
  2. Select your module under "Per-module bytecode version:"
  3. Click the red "-" button to delete the custom setting
  4. Click Apply

I think this bytecode setting (16) was conflicting with the one configured in my project (11). Removing the override cleared it up.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Andrew Kirna
  • 1,346
  • 16
  • 18
2

At the moment, it won't work with JDK 17, so it is suggested to use embedded Java provided from IDE in Settings/Gradle.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zakiblacki
  • 187
  • 1
  • 10
1

In Spring Tool Suite (STS)/Eclipse even after changing the build path, compiler, default JRE from 16 to 11.0 it did not fix. Finally in the STS.ini file, I had to change the -vm argument from

-vm plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149/jre/bin

to

-vm C:\Program Files\Java\jdk-11.0.12\bin

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Prashant S
  • 349
  • 4
  • 14
1

I fixed it by installing the Chocolatey package manager and running

choco install -y nodejs.install openjdk8

in PowerShell admin.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Joel V98
  • 401
  • 4
  • 2
0

I got the same error. This happens due to the different versions of java. You can find the error msgs according to the versions that it related. 19 - 63 18- 62 17- 61 16- 60 15- 59 14- 58 13- 57 12- 56 11- 55 10- 54 9 -53 8 -52

so you have to do is go to the project structure and through that change the SDK and version of your project according to the above table and then compile.Also, refer to this attached image. enter image description here