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:
1 2 3 4 |
$ 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:
1 2 |
$ javac -version javac 11 |
Maven version
It’s also important to double-check the Maven configuration:
1 2 3 4 5 6 7 |
$ 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
1 |
$ mvn clean install |
command or directly in the IntelliJ UI.
Photo by Clem Onojeghuo on StockSnap