
解决Maven编译项目报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
·
一、问题:
mvn compile
命令编译项目,生成target文件时,报一下错误:
[INFO] BUILD FAILURE
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project maven-pom-build-05: Fatal error compiling: 无效的目标发行版: 17 -> [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
二、解决方法
这种错基本上就是系统环境变量JDK版本与IDEA中使用的jdk版本不一致。
我的本机maven插件版本是:apache-maven-3.6.3,IDEA中在maven<properties>中使用的是:jdk17
我的系统环境变量JAVA_HOME配置的jdk版本是:jdk1.8.0_131
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
这就导致版本冲突了。
错误原因,执行java -version默认使用系统环境变量JAVA_HOME,
错误一、而maven优先使用了windows的用户变量JAVA_HOME(这里之前忘记修改,仍然指向java1.8路径),修改用户变量JAVA_HOME指向java17或删除该用户变量JAVA_HOME(如无它用)后即可。
错误二、系统环境变量指向的不是IDEA里面maven使用的版本号,这里将其重新修改成jdk17的安装路径即可。(我的错误就是这样)
修改之后,重启IDEA,设置才能在IDEA中生效。
再使用 :
mvn clean compile
命令即可解决问题。
更多推荐
所有评论(0)