Maven fails with “Fatal error compiling: invalid target release: 11” when it compiles a Java 11 project with JDK 8. A JDK can only build class files for its own version or older, and JDK 8 doesn’t know Java 11. The fix is to run Maven on JDK 11 or newer, or lower the version in pom.xml if the project must stay on Java 8.
Quick fix: run mvn -v. If the Java version line starts with 1.8, install JDK 11 (or newer) and point JAVA_HOME to it:
mvn -vexport JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64mvn clean install
The errors and fixes on this page were reproduced on Ubuntu 24.04 with Maven 3.8.7, OpenJDK 8, 11, 17 and 21, and maven-compiler-plugin 3.1 (the Maven 3.8 default), 3.8.1, 3.10.1, 3.11.0, 3.12.1, 3.13.0 and 3.16.0.
The Error Messages
Here is the full error from our test, a project with maven.compiler.source and target set to 11, built on JDK 8:
[INFO] Compiling 1 source file with javac [debug target 11] to target/classes
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile
(default-compile) on project demo: Fatal error compiling: invalid target release: 11 -> [Help 1]
Other messages with the same cause:
| Message | Where you see it |
|---|---|
invalid flag: --release | The pom uses <release>11</release> or maven.compiler.release, Maven runs on JDK 8 and maven-compiler-plugin is 3.12.1 or older. JDK 8 has no --release option. |
javac: invalid source release: 11 | Running javac -source 11 from JDK 8 directly. |
Error:java: invalid source release: 11 | IntelliJ IDEA, when the project SDK is JDK 8 but the language level is 11. |
Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)' | Gradle running on JDK 8 with sourceCompatibility or targetCompatibility set to 11. |
invalid target release: 9, 10, … | The same problem for any version newer than your JDK. |
Watch Out: A “Java 11” Project Can Build on JDK 8 Without an Error
If the pom sets the version with release (not source/target) and Maven runs on JDK 8, maven-compiler-plugin 3.13.0 and newer quietly skip the release setting and report BUILD SUCCESS. In our test the class files came out as Java 8 (class file version 52), not Java 11 (version 55).
You find out later, when the code uses something added after Java 8. For example, var s = "hi"; s.isBlank(); failed with cannot find symbol, an error that doesn’t mention Java versions at all. If a build works for your teammates but fails for you with “cannot find symbol” on standard Java methods, run mvn -v: you’re probably on JDK 8. Plugin versions 3.8.1 to 3.12.1 fail with invalid flag: --release instead, which is at least easier to understand.
Step 1: Check Which JDK Maven Uses
Maven uses the JDK in JAVA_HOME. Only when it’s empty does Maven fall back to the java on your PATH. So java -version can show 11 while Maven still uses JDK 8:
mvn -vjava -versionecho $JAVA_HOME
On Windows, use echo %JAVA_HOME% in Command Prompt or $env:JAVA_HOME in PowerShell. Java 8 reports itself as 1.8:
Apache Maven 3.8.7
Maven home: /usr/share/maven
Java version: 1.8.0_514, vendor: Ubuntu, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Fix 1: Install JDK 11 or Newer
Any JDK from 11 up can build a Java 11 project. If you’re installing fresh, JDK 17 or 21 is a better choice than 11. Just keep release at 11 in the pom, and the class files still run on Java 11.
| System | Command |
|---|---|
| Ubuntu 26.04 / 24.04, Debian | sudo apt install openjdk-11-jdk (or openjdk-17-jdk) |
| RHEL, Rocky Linux, AlmaLinux 8/9 | sudo dnf install java-11-openjdk-devel (or java-17-openjdk-devel) |
| macOS (Homebrew) | brew install openjdk@11 (or openjdk@17) |
| Windows | Install the JDK MSI from Eclipse Temurin (Adoptium) and tick “Set JAVA_HOME variable”. |
| Any OS, several versions | SDKMAN: sdk list java, then install the version you need |
Fix 2: Point JAVA_HOME to the New JDK
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64export PATH="$JAVA_HOME/bin:$PATH"mvn -v
Run ls /usr/lib/jvm to see the folder names on Ubuntu and Debian. When mvn -v shows 11 (or newer), add the two lines to ~/.bashrc or ~/.zshrc, and remove the old Java 8 JAVA_HOME line from ~/.bashrc, ~/.profile or /etc/environment.
- macOS:
export JAVA_HOME=$(/usr/libexec/java_home -v 11). See set JAVA_HOME on macOS. - Windows: change
JAVA_HOMEunder System Properties → Environment Variables and open a new terminal. See set JAVA_HOME on Windows. - Linux: set JAVA_HOME on Ubuntu and Linux Mint.
On Ubuntu and Debian without JAVA_HOME, switch the system default with sudo update-alternatives --config java and sudo update-alternatives --config javac. See managing multiple Java versions on Ubuntu.
Fix 3: Check the Version in pom.xml
For Java 11 and newer, set the version with the single release property and pin a current compiler plugin:
<properties>
<maven.compiler.release>11</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.16.0</version>
</plugin>
</plugins>
</build>
If the project has to stay on Java 8 (an old app server, for example), don’t use release. Set source and target to 1.8, which builds on JDK 8 and on any newer JDK:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
When everyone builds on JDK 9 or newer, <maven.compiler.release>8</maven.compiler.release> is the safer choice: in our test, JDK 11 built Java 8 class files with it, and it also blocks APIs that Java 8 doesn’t have.
Also check the parent pom and properties such as java.version, which some projects use to set the compiler version.
Fix It in IntelliJ IDEA, Eclipse and Gradle
- IntelliJ IDEA (“Error:java: invalid source release: 11”): set File → Project Structure → Project → SDK to JDK 11 or newer, and check each module’s language level on the Modules tab. For Maven builds, also set Settings → Build, Execution, Deployment → Build Tools → Maven → Runner → JRE. Then reload the Maven project.
- Eclipse: add the JDK under Window → Preferences → Java → Installed JREs, pick it on the JRE tab of your Maven Run Configuration, then run Maven → Update Project.
- Gradle (“Could not target platform: ‘Java SE 11′”): run Gradle on JDK 11 or newer (set
JAVA_HOME, or Settings → Build Tools → Gradle → Gradle JVM in IntelliJ), or let Gradle pick the JDK with a toolchain inbuild.gradle:java { toolchain { languageVersion = JavaLanguageVersion.of(11) } }. - CI and Docker: request the right JDK, for example
java-version: '11'withactions/setup-java@v6, or amaven:3.9-eclipse-temurin-17image instead of a-8one.
If Maven itself must stay on JDK 8 (an old build server), use a Maven toolchain to compile with JDK 11. The steps are in the Java 21 guide; replace 21 with 11.
Same Error with Other Versions
- Invalid target release: 17
- Invalid target release: 21 (also covers 25)
FAQ
Is Java 1.8 the same as Java 8?
Yes. Up to Java 8, versions were written as 1.x, so Java 8 shows up as 1.8.0_... in java -version and mvn -v. From Java 9 on, the “1.” was dropped. In the pom, 1.8 and 8 both mean Java 8.
Can JDK 8 compile Java 11 code?
No. JDK 8 can only target Java 8 and older. Install JDK 11 or newer.
Can JDK 17 or 21 build a Java 11 project?
Yes. In our test JDK 17 built a project with release 11 without problems. The class files run on Java 11.
Why does the build work in the terminal but fail in IntelliJ?
IntelliJ uses its own JDK settings (project SDK and Maven Runner JRE), not your shell’s JAVA_HOME. Set both to JDK 11 or newer.
Conclusion
“Invalid target release: 11” means Maven is compiling with JDK 8. Check mvn -v (Java 8 shows as 1.8), install JDK 11 or newer, and point JAVA_HOME, your IDE or your CI job to it. If the project must stay on Java 8, set source and target to 1.8. And don’t trust a “Java 11” build that passes on JDK 8: with compiler plugin 3.13.0 or newer, it may have quietly built Java 8 class files.
How did it make you feel?
