Java "Unsupported major.minor version" - Fix Runtime JDK in CI
An older JVM (pre-Java 8u51 message format) refused a class compiled by a newer JDK. The runtime is older than the compiler that produced the bytecode, so it cannot load the class.
What this error means
At class load, an older JVM throws java.lang.UnsupportedClassVersionError: ... Unsupported major.minor version 52.0. Compilation succeeded on a newer JDK; the older runtime rejects the result.
Exception in thread "main" java.lang.UnsupportedClassVersionError:
com/example/App : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)Common causes
Runtime JDK older than the compile JDK
Bytecode major version 52 = Java 8. An older JVM (Java 7) cannot load it. The compile and run stages used different, incompatible JDKs.
A dependency built for a newer Java
A library compiled for a newer Java than your runtime triggers the same error when its classes load.
How to fix it
Run on a JDK at least as new as the compile JDK
Provision a runtime JDK no older than the one that compiled the classes.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17' # runtime >= compile JDKOr target older bytecode at compile time
If the runtime must stay old, compile with a matching --release.
mvn -B -Dmaven.compiler.release=8 clean packageHow to prevent it
- Keep the runtime JDK at least as new as the compile JDK, or target an older
--releasewhen running on older JVMs.