Categories: Tools

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

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:

$ java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

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

$ javac -version
javac 11

Maven version

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

$ mvn --version
Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 11, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk-11
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-43-generic", arch: "amd64", family: "unix"

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:

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

Java Compiler and Maven Runner

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

and Java Compiler settings:

Compile your project

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

$ mvn clean install

command or directly in the IntelliJ UI.

Photo by Clem Onojeghuo on StockSnap

little_pinecone

Recent Posts

Simplify the management of user roles in Spring Boot

Spring Security allows us to use role-based control to restrict access to API resources. However,…

3 years ago

Create a custom annotation to configure Spring Boot tests

A custom annotation in Spring Boot tests is an easy and flexible way to provide…

3 years ago

Keycloak with Spring Boot #4 – Simple guide for roles and authorities

Delegating user management to Keycloak allows us to better focus on meeting the business needs…

3 years ago

Keycloak with Spring Boot #3 – How to authorize requests in Swagger UI

Swagger offers various methods to authorize requests to our Keycloak secured API. I'll show you…

3 years ago

Keycloak with Spring Boot #2 – Spring Security instead of Keycloak in tests

Configuring our Spring Boot API to use Keycloak as an authentication and authorization server can…

3 years ago

Keycloak with Spring Boot #1 – Configure Spring Security with Keycloak

Keycloak provides simple integration with Spring applications. As a result, we can easily configure our…

3 years ago