Maven compilation always prompts the solution of invalid target release version

摘自个人印象笔记2021-05-07:https://app.yinxiang.com/fx/55e1d5f4-aeea-446a-a768-0f1a48195f5b(图显示不完整可查看原笔记内容)

1: Make sure that the compiled version in the IDE is correct.
In the idea, it mainly depends on whether the corresponding jdk version in the project properties and the java compiler of the setting is correct, as follows:
View in the project properties:

View in setting:

2: Make sure that the maven-compiler-plugin plugin in the pom file is configured correctly

org.apache.maven.plugins maven-compiler-plugin 3.1 1.9 1.9

3: If the mvn compile compile prompts the following exception information:

[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.
You can use the following command to display mvn compilation details :

mvn -X -U clean compile

4: If the above items 1 and 2 are correct, but still prompts "invalid target release version", you need to pay attention:
use the following command to check which version of jdk is used by mvn:

mvn -version
outputs the following words:

Note that the Java version represents the jdk version used by maven, and this version should correspond to the source and target versions configured in the maven-compiler-plugin plugin!
For example, the compiled version configured in the above figure is 1.9, but maven actually uses jdk 1.8, it will prompt "Invalid target found version: 1.9"! ! !

Principle:
Maven obtains the Java version from the JAVA_HOME variable instead of the PATH environment variable, so even if the machine is configured with a default jdk of 1.9, because JAVA_HOME points to another jdk, there will be a problem with the compiled version!

Guess you like

Origin blog.csdn.net/AJian759447583/article/details/132224043