IntelliJ Maven: Fatal error compiling: invalid flag: --release
Codemia Knowledge Hub ·
Maven is running a Java compiler that is too old to understand --release. IntelliJ can show one JDK in the project settings while Maven actually runs with another, which is what makes this error confusing.
Why an old JDK rejects --release
--release is a javac option from newer Java toolchains that compiles cleanly against a specific Java platform level:
If the compiler process is really JDK 8, the flag is invalid and Maven fails before compilation starts. So the error is a toolchain mismatch, not a code problem.
Where the mismatch hides
Check three places:
- the JDK configured for the IntelliJ project
- the JDK used by Maven inside IntelliJ
- the compiler settings in
pom.xml
A project may target Java 17 in pom.xml while IntelliJ runs Maven with Java 8 from JAVA_HOME or its own Maven runner settings. IntelliJ can compile with its configured SDK and still hand Maven tasks to a different JDK, so the editor and the project SDK look fine while the Maven build fails. Maven is a separate process with its own Java selection.
A typical Maven setup using release:
This works only when Maven runs on a compatible JDK.
Checking which Java Maven uses
If this reports Java 8 while pom.xml uses maven.compiler.release, you have found the problem. In IntelliJ, also check the Maven runner JDK. The project SDK and the Maven import/runner JDK are related, but they are not always the same setting.
Fixes
Run Maven with a newer JDK
If the project is meant for Java 11, 17 or later, point IntelliJ and Maven at that JDK and keep maven.compiler.release.
Use source and target for JDK 8 builds
If the project really must build with JDK 8, replace release with source and target:
This stops asking an old compiler for a flag it does not support.
Align every setting
Make sure these agree:
JAVA_HOME- IntelliJ project SDK
- IntelliJ Maven runner JDK
- the Java version declared in
pom.xml
Most --release errors disappear once the toolchain is aligned end to end.
Fixes that don't work
- Checking only the IntelliJ project SDK. It is often not the JDK Maven uses.
- Downgrading the compiler plugin. The plugin matters, but the JDK actually running
javacmatters more. - Switching blindly between
release,sourceandtarget. Pick the configuration that matches the toolchain you actually intend to support.
Related reading
- IntelliJ Never use wildcard imports
- IntelliJ Process finished with exit code 0 when spring-boot run
- intellij run configuration can't find spring boot class
- IntelliJ show JavaDocs tooltip on mouse over
- Intellij, target JRE vesion doesn''t match project jdk version
- intercepting session set attribute call
- Interceptor not getting initialized and invoked with SpringBoot
- Interface naming in Java

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.