Debugging the “Fatal error compiling: invalid target release: 11” issue. How to switch your development environment and IntelliJ settings to Java 11

featured_image

When updating to Java 11 from an older version of the language, make sure that your development environment is up to date. Otherwise you will receive the

"Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project: Fatal error compiling: invalid target release: 11"

error while building a project with Maven. Follow the checklist in this post to adjust the required settings for building a Spring Boot application.

JDK version

Have you installed the appropriate JDK? Run this command to verify which version will be used:

Make sure that you have the matching compiler, check out its version with the following command:

Maven version

It’s also important to double-check the Maven configuration:

The output of the above command reveals not only the version of Maven currently installed on your machine, but also the value of the JAVA_HOME variable and the Java version used by the tool.

IDE settings

The fatal compilation error can also occur if you compile projects through your IDE interface without updating its settings.

Project structure

To verify the settings you need to go to File → Project Structure and check the Project SDK and Project Language Level. If the JDK for Java 11 is missing, you can add it by clicking the New… button, selecting +JDK and choosing the proper directory in the Select Home Directory for JDK window:

Project Structure - Project screenshot

Furthermore, verify the Language level for Modules in your project:

Project Structure - Modules screenshot

Java Compiler and Maven Runner

Additionally, you can go to File → Settings → Build, Execution, Deployment and verify the Maven Runner settings:

Settings - Maven screenshot

and Java Compiler settings:

Settings - Java Compiler screenshot

Compile your project

Clean the files and directories generated by Maven during the failed build and compile your project again either with the

command or directly in the IntelliJ UI.

Photo by Clem Onojeghuo on StockSnap

Leave a Reply

Your email address will not be published. Required fields are marked *