Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Error: Unsupported Class File Version 66 with Java 22 - How to Resolve?

The issue I'm encountering is related to using Gradle with Java 22. When attempting to run a Gradle build, I'm encountering the following error:

Could not open cp_init generic class cache for initialization script 'C:\Users\mahendra_narada\AppData\Roaming\Code\User\workspaceStorage\817674aa27f755155b7d9dabc7fd3ea5\Oracle.oracle-java\userdir\var\cache\gradle\nb-tooling.gradle' (C:\Users\mahendra_narada\.gradle\caches\7.5\scripts\d6xbftyinmb8c7v2qcj0zlw41). BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66

This error indicates that there's an unsupported class file version (version 66) being encountered during the Gradle build process. I suspect this is due to Gradle attempting to use a Java version that doesn't support class file version 66, which is specific to Java 22.

I've tried setting the sourceCompatibility and targetCompatibility in my Gradle configuration to JavaVersion.VERSION_1_8, but the issue persists.

I'm seeking guidance on how to properly configure Gradle to work with Java 22 or if there are any other steps I can take to resolve this issue. Any insights or suggestions would be greatly appreciated.

I initially attempted to resolve the issue by setting the sourceCompatibility and targetCompatibility in my Gradle configuration to JavaVersion.VERSION_1_8. My expectation was that this configuration would restrict the Java version used by Gradle to Java 8, thereby avoiding the unsupported class file version error encountered with Java 22.

However, despite this configuration change, the issue persisted, indicating that Gradle was still attempting to use a Java version incompatible with class file version 66 (specifically, Java 22).

Since then, I've also tried verifying my Gradle version to ensure compatibility with Java 22 and setting the JAVA_HOME environment variable to point to the directory of my Java 22 installation. Additionally, I've checked for any custom initialization scripts that might be explicitly configuring Gradle to use an incompatible Java version.

Despite these efforts, the issue remains unresolved, and I'm seeking further guidance on how to properly configure Gradle to work with Java 22 or any other potential solutions to resolve the unsupported class file version error.

like image 263
narada mahendra Avatar asked Feb 03 '26 15:02

narada mahendra


1 Answers

You are apparently using a version of Gradle that doesn't support Java 22. sourceCompatibility and targetCompatibility have nothing to do with the version that is used to execute Gradle.

Try adding the bin directory of a previous version of Java -compatible with your version of Gradle- to the beginning of the environment PATH variable.

Example:

C:\> PATH=path/to/jdk8/bin;%PATH%

Alternatively upgrade your project Gradle wrapper to the latest version of Gradle to ensure JDK 22 support:

gradle wrapper --gradle-version 8.8
like image 78
aled Avatar answered Feb 06 '26 06:02

aled



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!