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.
* What went wrong:
Could not open cp_init generic class cache ...
> BUG! exception in phase 'semantic analysis' ...
Unsupported class file major version 65Common 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).
./gradlew wrapper --gradle-version 8.8
# commit the updated gradle/wrapper/gradle-wrapper.propertiesRun 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.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17' # JDK that runs Gradle
# project can still target 21 via a Java toolchain blockHow 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.