17

When I create a new project using the Spring initializr Gradle won't build the project. I use IntelliJ IDEA.

The error message is

* Exception is:
org.gradle.cache.CacheOpenException: Could not open init generic class cache for initialization script '/tmp/ijmapper.gradle' (/home/julius/.gradle/caches/7.6.1/scripts/dnnmnny7cynyzgkf00s30jlld).
    at org.gradle.cache.internal.DefaultPersistentDirectoryStore.open(DefaultPersistentDirectoryStore.java:91)
    ... 166+ more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 64

I looked it up using this table, it's java 20. The issue is, that I didn't select Java-20, I chose Java-17. On top of that, I'm not able to install Java-20 on my Linux machine yet.

Julius Babies
  • 955
  • 3
  • 6
  • 22

4 Answers4

36

I've found the problem: My Gradle settings were trying to use Java 20. I solved it by clicking on Gradle -> the little cogwheel -> Gradle Settings and setting Gradle JVM to 17.

Julius Babies
  • 955
  • 3
  • 6
  • 22
8

I know that I am a bit late to this thread. However, I just ran into this issue, and I found that updating gradle-wrapper.jar solves this. I did so by running ./gradlew wrapper --gradle-version=8.1.1 --distribution-type=bin in my project directory.

Source: https://gradle.org/install/#helpful-information

4

The gradle wrapper version needs to be updated. The command I tried is as below

gradle wrapper --gradle-version 8.1.1

Reference: https://docs.gradle.org/current/userguide/upgrading_version_7.html

Jay
  • 9,189
  • 12
  • 56
  • 96
1

I assume that you are using some kind of IDE, Eclipse or IntelliJ, or whatever. How IDE works is that it is an isolated ecosystem with already predefined JDK/JRE.

I know for a fact when you install a new Eclipse and if you

  1. Right-click on your project

  2. Properties

  3. Java Build Path

  4. Libraries Tab

  5. Click on JRE System Library

  6. Click on Edit

  7. Installed JRE

In that window, Eclipse will have one of the latest JDKs set as a default, which has nothing to do with the JDK that you have installed on your system. So for example, if you downloaded the latest Eclipse it will have the latest JDK set there that is part of Eclipse, and that is the value that needs to be deleted, and you explicitly set JDK that you want to use, that is 17 in your example. The same goes for the IDE compiler version, you also need to check if it has the correct value, which is 17 in your example.

Eclipse has Installed JRE and Java Compiler, IntelliJ has SDKs and Java Compiler.

As of IntelliJ places for JDK

  1. File > Settings > Build > Compiler > Java Compiler

  2. File > Project Settings > SDK and Language level should be 17

  3. File > Project Settings > Modules > Dependencies tab should have 17 on top

  4. File > Project Settings > Modules > Sources tab should have 17 on top –

Also please keep in mind that you also need to make sure that you have JDK17 in your pom/gradle file as well.

zawarudo
  • 1,907
  • 2
  • 10
  • 20