Skip to content
Latchkey

javac "invalid flag: --release" in CI - Fix Compiler Flag Support

The compiler rejected the --release flag because it is running on a JDK that predates it. --release was introduced in JDK 9; a JDK 8 (or older) javac does not recognize it.

What this error means

Compilation fails immediately with invalid flag: --release (often surfaced through Maven’s <release> or Gradle’s release option). The running compiler is JDK 8 or earlier.

mvn output
[ERROR] Failed to execute goal ...:compile ...
Fatal error compiling: invalid flag: --release
# the build sets <release> but javac is JDK 8

Common causes

Old JDK without --release support

The build configures --release, but the JDK running the compile is 8 or earlier, where that flag does not exist.

Ambient JDK older than the config assumes

CI picked up an old default JDK while the POM/build was written assuming JDK 9+. The flag is valid config, wrong compiler.

How to fix it

Provision JDK 9+ (or current) in CI

A modern JDK supports --release. Pin one and verify it.

.github/workflows/ci.yml
- uses: actions/setup-java@v4
  with:
    distribution: temurin
    java-version: '17'
- run: javac --release 17 -version

Or use source/target on JDK 8

If you must stay on JDK 8, replace <release> with <source>/<target>.

pom.xml
<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

How to prevent it

  • Use a current JDK in CI so --release is supported.
  • Pin the JDK with setup-java and assert the version.
  • Reserve source/target for genuine JDK 8 builds.

Related guides

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