IntelliJ
Maven
Compilation Error
Java
--release Flag

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:

bash
javac --release 17 Hello.java

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:

xml
1<properties>
2    <maven.compiler.release>17</maven.compiler.release>
3</properties>
4
5<build>
6    <plugins>
7        <plugin>
8            <groupId>org.apache.maven.plugins</groupId>
9            <artifactId>maven-compiler-plugin</artifactId>
10            <version>3.11.0</version>
11        </plugin>
12    </plugins>
13</build>

This works only when Maven runs on a compatible JDK.

Checking which Java Maven uses

bash
mvn -version

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:

xml
1<properties>
2    <maven.compiler.source>1.8</maven.compiler.source>
3    <maven.compiler.target>1.8</maven.compiler.target>
4</properties>

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 javac matters more.
  • Switching blindly between release, source and target. Pick the configuration that matches the toolchain you actually intend to support.

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data 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.

Practice algorithms