Skip to content
Latchkey

Gradle "Unsupported class file major version" - Fix JDK

Gradle (or one of its plugins, like ASM) refused a class file because it was compiled by a JDK newer than Gradle supports. This is about the JDK running Gradle itself, not your project’s target.

What this error means

Gradle fails very early during configuration with Unsupported class file major version N, before your code compiles. The number maps to a JDK: 61=17, 65=21, 66=22, 67=23.

gradle output
* What went wrong:
Could not open cp_init generic class cache ...
> BUG! exception in phase 'semantic analysis' ...
   Unsupported class file major version 65

Common causes

Gradle version too old for the JDK

Each Gradle release supports JDKs up to a known version. Running an old Gradle (e.g. 7.x) on JDK 21 produces class files Gradle’s embedded ASM cannot read.

JAVA_HOME points at a too-new JDK

CI provisioned the newest JDK and Gradle picked it up. The Gradle runtime, not your build, is what is incompatible.

How to fix it

Upgrade the Gradle wrapper

Bump the wrapper to a version that supports your JDK (e.g. Gradle 8.5+ for JDK 21).

Terminal
./gradlew wrapper --gradle-version 8.8
# commit the updated gradle/wrapper/gradle-wrapper.properties

Run Gradle on a supported JDK

Keep your project targeting a newer Java via toolchains, but run the Gradle process itself on a JDK that this Gradle version supports.

.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: temurin
    java-version: '17'   # JDK that runs Gradle
# project can still target 21 via a Java toolchain block

How to prevent it

  • Keep the Gradle wrapper current with the JDKs your CI provisions.
  • Use Java toolchains so the compile JDK is decoupled from the Gradle-runtime JDK.
  • Commit gradle-wrapper.properties so everyone runs the same Gradle version.

Frequently asked questions

What causes ""Unsupported class file major version""?
Each Gradle release supports JDKs up to a known version. Running an old Gradle (e.g. 7.x) on JDK 21 produces class files Gradle’s embedded ASM cannot read.
How do I fix "Unsupported class file major version"?
Bump the wrapper to a version that supports your JDK (e.g. Gradle 8.5+ for JDK 21).

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card