Skip to content
Latchkey

Gradle "Unsupported class file major version" (JDK mismatch) in CI

ASM inside Gradle read a class compiled for a JDK newer than the JVM running Gradle. The number (for example 65 for Java 21) tells you which JDK the class needs, and it exceeds the JDK on the runner.

What this error means

The build fails early with "Unsupported class file major version NN", often while Gradle or a plugin processes bytecode, before your own compilation runs.

Gradle
FAILURE: Build failed with an exception.
* What went wrong:
Could not open cp_proj generic class cache for build file '.../build.gradle'.
> BUG! exception in phase 'semantic analysis' ...
  > Unsupported class file major version 65

Common causes

Gradle runs on an older JDK than a plugin needs

A plugin or dependency was built for a newer Java (major version 65 = Java 21), but the runner launched Gradle with an older JDK that cannot read it.

The runner default JDK is too old for this Gradle

The Gradle version itself requires a newer JDK than the one setup-java selected as default.

How to fix it

Run Gradle on a matching JDK

  1. Map the major version to the required Java release (65 = 21, 61 = 17).
  2. Select that JDK for the job with setup-java.
  3. Re-run so Gradle launches under the correct JVM.
.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: temurin
    java-version: '21'

Separate the Gradle JVM from the compile toolchain

Run Gradle on a JDK new enough for its plugins, and pin your code compilation via a Java toolchain so the two do not conflict.

build.gradle.kts
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

How to prevent it

  • Run Gradle on a JDK at least as new as its plugins require.
  • Pin compilation with a Java toolchain, separate from the launch JDK.
  • Keep setup-java and Gradle versions aligned.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →