Skip to content
Latchkey

Gradle "Could not determine java version from" in CI

The gradlew launcher reads the JDK version before starting the daemon. When the JDK at JAVA_HOME reports a version the running Gradle does not understand (often a JDK newer than that Gradle supports), the launcher aborts before any task runs.

What this error means

The build fails immediately with "Could not determine java version from '21.0.2'." or a similar version string, before configuration starts.

Gradle
ERROR: Could not determine java version from '21.0.2'.

Common causes

The JDK is newer than the Gradle version supports

An old Gradle cannot parse a newer JDK version string, so it refuses to launch on that JAVA_HOME.

JAVA_HOME points at a non-JDK or broken install

If JAVA_HOME resolves to a path with no usable java -version, the launcher cannot read a version at all.

How to fix it

Align the JDK and Gradle versions

  1. Pin a JDK the running Gradle supports with setup-java, or upgrade Gradle to support the JDK.
  2. Confirm JAVA_HOME points at that JDK on the runner.
  3. Re-run the build.
.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: 'temurin'
    java-version: '17'

Upgrade the wrapper to support a newer JDK

If you must run a newer JDK, bump the Gradle wrapper to a version that understands it.

Terminal
./gradlew wrapper --gradle-version 8.7

How to prevent it

  • Keep the Gradle wrapper and the runner JDK on compatible versions.
  • Pin the JDK with setup-java rather than relying on the image default.
  • Check a Gradle release note for its supported JDK range before bumping JDKs.

Related guides

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