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.
[ERROR] Failed to execute goal ...:compile ...
Fatal error compiling: invalid flag: --release
# the build sets <release> but javac is JDK 8Common 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.
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- run: javac --release 17 -versionOr use source/target on JDK 8
If you must stay on JDK 8, replace <release> with <source>/<target>.
<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
--releaseis supported. - Pin the JDK with setup-java and assert the version.
- Reserve
source/targetfor genuine JDK 8 builds.