When try to build the maven java project using mvn clean install or mvn package, you may get this error if maven java version and project java version mismatches.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project spring-boot-postgresql-crud: Fatal error compiling: invalid target release: 11 -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
The error is invalid target release: 11 - that means the project’s Java version is 11 but Maven is running under lower JDK version.
Need to check maven version which compatible with java version.
you can use the maven command, version -> mvn -version,
command prompt - maven version command |
So maven compatible java version is 1.8 or below versions.
Solutions:-
1) Changing the project java version i.e compatible java maven version - here it's java 1.8
If project is a spring boot web application then change pom.xml java version as follows,
<properties> <java.version>1.8</java.version> </properties>
<properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> </properties>
2) Changing maven's java version
If you don't want to change the project java version then change maven java version, install and new jdk(i.e 11 here) and set the environment variables i.e JAVA_HOME should point to the new jdk path.
3) Changing runtime JRE in IDE(Eclipse, Intellij)
We can fix this issue in developer tool/ide like eclipse or intellij if you are using these tools to build,
Select Project -> Go to run configurations -> maven build then select or click on JRE
the default or selected JRE should be greater than or equal to the version of the project java version, in the mentioned issue here need to select jre version as 11.
Thank you for reading the blog.