Skip to content
Latchkey

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.

java runtime
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.

.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: temurin
    java-version: '17'   # runtime >= compile JDK

Or target older bytecode at compile time

If the runtime must stay old, compile with a matching --release.

Terminal
mvn -B -Dmaven.compiler.release=8 clean package

How to prevent it

  • Keep the runtime JDK at least as new as the compile JDK, or target an older --release when running on older JVMs.

Related guides

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