Главная » Error » Maven error – invalid target release: 17 – Mkyong

Maven error – invalid target release: 17 – Mkyong

1. Find out the Java version in Maven

The Maven may be using a different Java version to compile the project, and we can use mvn -version to find out the Maven details.

Terminal
mvn -version

Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: /usr/local/Cellar/maven/3.8.3/libexec
Java version: 11.0.10, vendor: Oracle Corporation, runtime: /usr/local/Cellar/openjdk@11/11.0.10/libexec/openjdk.jdk/Contents/Home
Default locale: en_MY, platform encoding: UTF-8
OS name: “mac os x”, version: “11.6”, arch: “x86_64”, family: “mac”

Try print out the JAVA_HOME environment variable; Maven finds JAVA_HOME for Java to compile.

Terminal
echo $JAVA_HOME
/usr/local/Cellar/openjdk@11/11.0.10/libexec/openjdk.jdk/Contents/Home

The Maven is still using Java 11.

2. Solution – Update JAVA_HOME

Updating the JAVA_HOME environment variable and ensuring it points to the correct JDK.

2.1 For macOS, open the ~/.zshenv and update the JAVA_HOME to Java 17

The JAVA_HOME is pointing to Java 11.

~/.zshenv
export JAVA_HOME=$(/usr/libexec/java_home -v 11)

We upgraded the JAVA_HOME to Java 17.

~/.zshenv
export JAVA_HOME=$(/usr/libexec/java_home -v 17)

2.2 source the ~/.zshenv or reopen the shell to reflect the change of the JAVA_HOME.

Terminal
source ~/.zshenv

2.3 Recheck Maven’s Java version.

Terminal
mvn -version

Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: /usr/local/Cellar/maven/3.8.3/libexec
Java version: 17, vendor: Oracle Corporation, runtime: /Users/yongmookkim/Library/Java/JavaVirtualMachines/openjdk-17/Contents/Home
Default locale: en_MY, platform encoding: UTF-8
OS name: “mac os x”, version: “11.6”, arch: “x86_64”, family: “mac”

Note
For Windows or Linux, find the JAVA_HOME environment variable and ensure it is pointing to the correct JDK.

3. Fix invalid target release error in IDE

If you encounter the Maven error invalid target release in your IDE such as Eclipse or Spring Tool Suite, follow these steps:

– Open the Run Configurations dialog (Go to menu Run > Run Configurations)

– Select the Run configuration that you use to run Maven build

– Click JRE tab. Then choose the Runtime JRE that has version greater than or equal to your project’s Java version.

edit run configuration maven

Refer to this article to learn more: How to manage JRE installations in Eclipse.

To see how to fix the Maven build error invalid target release in action, watch the following video:

Video:

 

2. Fix invalid target release error by changing Maven’s Java version

Apply this solution if the project’s Java version cannot be lower. That means you need to have another JDK newer than the one that runs Maven. You can check by typing:

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):

  • Download and install Oracle JDK 17
  • How to set JAVA_HOME environment variable

Note that you need to open a new command prompt window after updating the environment variables.

Источники

  • https://mkyong.com/maven/maven-error-invalid-target-release-17/
  • https://www.codejava.net/tools/maven/fix-error-invalid-target-release
[свернуть]
Решите Вашу проблему!


×
Adblock
detector