How to Solve Error Message Failed to execute goal org.apache.maven.plugins maven-compiler-plugin 3.8.1 compile (default-compile) on project Fatal error compiling invalid target release

Posted on

Introduction

This article is showing how to solve an error message. The error message appear in the title of this article. Actually, it is an error appear when building and compiling a Java-based application using the Netbeans IDE. It is a project using Spring Boot Framework where the error exist below :

How to Solve Error Message Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 -> [Help 1]

Furthermore, the full complete error appears in the following actual error :

cd C:\Users\Personal\Documents\NetBeansProjects\InitializrSpringbootProject; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_111" M2_HOME=C:\\apache-maven-3.6.3 cmd /c "\"\"C:\\apache-maven-3.6.3\\bin\\mvn.cmd\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" clean install\""
Scanning for projects...

--------------------------< com.example:demo >--------------------------
Building demo 0.0.1-SNAPSHOT
--------------------------------[ jar ]---------------------------------

--- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
Deleting C:\Users\Personal\Documents\NetBeansProjects\InitializrSpringbootProject\target

--- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
Using 'UTF-8' encoding to copy filtered resources.
Using 'UTF-8' encoding to copy filtered properties files.
Copying 1 resource
Copying 0 resource

--- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
Changes detected - recompiling the module!
Compiling 3 source files to C:\Users\Personal\Documents\NetBeansProjects\InitializrSpringbootProject\target\classes
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time:  2.710 s
Finished at: 2021-06-28T07:03:24+07:00
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

For more information, the following is the content of the pom.xml file :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

The above pom.xml file describe the project build and compile process. But the main problem exist while using the above pom.xml file to build and compile the project.

Solution

Actually, the solution is very simple to solve the problem. The main problem is that the compilation stuck because of the maven-compiler-plugin cannot compile and it is considered as an error compile. The reason for the incapability is because of invalid target release: 11. So, just remove by commenting the following element from the pom.xml file of the Java application project.  :

Fatal error compiling: invalid target release: 11 -> [Help 1]
<!--
<properties>
<java.version>11</java.version>
</properties>
-->

After saving the changes to the pom.xml file, just run the build and compile process again once more. If there are no more errors available, the build and compile process will be a success.

One thought on “How to Solve Error Message Failed to execute goal org.apache.maven.plugins maven-compiler-plugin 3.8.1 compile (default-compile) on project Fatal error compiling invalid target release

  1. caused by: org.apache.maven.plugin.MojoExecutionException: Fatal error compiling

Leave a Reply