Java "class file has wrong version" - Fix Dependency Bytecode Mismatch
javac found a dependency class compiled for a newer Java than your project targets. The compiler reads the class-file version, sees it is higher than your --release, and refuses it.
What this error means
Compilation fails with class file has wrong version 65.0, should be 61.0 while reading a dependency. Your own code is fine; a library on the classpath was built for a newer Java than your target.
error: cannot access SomeLibraryClass
bad class file: .../somelib-3.0.0.jar(com/lib/SomeLibraryClass.class)
class file has wrong version 65.0, should be 61.0
Please remove or make sure it appears in the correct subdirectory of the classpath.Common causes
Dependency built for a newer Java
A library you depend on was compiled for Java 21 (class version 65) while you compile against Java 17 (61). javac cannot read the newer bytecode at that target.
Compile target lower than the dependency requires
An upgraded dependency raised its minimum Java. Your --release/toolchain stayed on the older version, creating the mismatch.
How to fix it
Raise your compile target and JDK
Compile against a Java version at least as new as the dependency requires.
# Maven
<maven.compiler.release>21</maven.compiler.release>
# plus provision JDK 21 in CI (setup-java java-version: '21')Or pin a dependency version for your target
If you must stay on an older Java, use a dependency release that still targets it.
# downgrade to a release built for Java 17
<dependency>
<groupId>com.lib</groupId>
<artifactId>somelib</artifactId>
<version>2.8.0</version> <!-- last Java 17-compatible release -->
</dependency>How to prevent it
- Track the minimum Java required by your dependencies and keep your target aligned.
- Pin dependency versions so a transitive upgrade does not silently raise the Java floor.
- Run a CI matrix on your supported Java versions.