[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ProjectName: Fatal error compiling: error: invalid target release: 17 -> [Help 1]The error is invalid target release: 17 - that means the project’s Java version is 17 but Maven is running under lower JDK version. To see the version of JDK that runs Maven, type mvn -v and you will see something like this:
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: g:\apache-maven-3.6.3\bin\.. Java version: 15, vendor: Oracle Corporation, runtime: g:\OpenJDK15\jdk-15That means Maven is using Java version 15, whereas the project uses Java version 17, hence that invalid target release error.So to fix this kind of error, you can either:- Change Java version of the project to the one that less than or equal to the version of JDK that runs Maven.- Change the JDK that runs Maven, to be greater than or equal the project’s Java version
<properties> <java.version>11</java.version> </properties>This is for a Spring Boot project. For a general Maven project, you may need to update as follows:
<properties> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties>
<configuration> <release>13</release> </configuration>Then run mvn package again, the invalid target release error will be gone.
java -version
Or:mvn -v
You need to install a newer JDK and then update JAVA_HOME or PATH environment variables. Follow my guides here (for example, install JDK 17):Note that you need to open a new command prompt window after updating the environment variables.