Saturday 24 June 2023

Maven build error: Fatal error compiling: invalid flag: --release -> [Help 1]

 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] 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] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]

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.


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,


If project is general java project, then need to update pom.xml file as follows,


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

Invalid target maven build issue fix in IDE
Invalid target relase issue fix in IDE

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.

No comments:

Post a Comment