针对Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解决方案

来源:互联网 发布:老司机网络用语 编辑:程序博客网 时间:2024/06/05 00:27

针对Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解决方案

背景:本项目使用JDK1.8
编译maven工程的时候出现如下错误:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1
pom中如下配置maven插件,配置中声明使用JDK1.8:

<plugin>      <groupId>org.apache.maven.plugins</groupId>      <artifactId>maven-compiler-plugin</artifactId>      <version>3.1</version>      <configuration>          <verbose>true</verbose>          <fork>true</fork>          <executable>${JAVA8_HOME}/bin/javac</executable>      </configuration>  </plugin>  

这里的${JAVA8_HOME}这个变量是在settings.xml中配置的,如下:

<profile>       <id>custom-compiler</id>       <properties>           <JAVA8_HOME>C:\Program Files (x86)\Java\jdk1.8.0_73</JAVA8_HOME>       </properties>  </profile>  

当然这里应该需要激活,所以settings.xml文件还应该有如下配置:

<activeProfiles>          <activeProfile>custom-compiler</activeProfile>  </activeProfiles> 

从pom文件中CTRL点击变量JAVA8_HOME能跳到settings.xml中找到它的定义处,按理来说应该是能找到这个变量,出现上述问题并不是因为找不到这个变量。我将pom文件中的JAVA8_HOME这个变量直接用实际的路径替换,即替换为

C:\Program Files (x86)\Java\jdk1.8.0_73\bin\javac 

发现编译通过,这就奇怪了。
揭晓原因:

maven其实是有一个默认的仓库.m2仓库和默认的settings.xml配置文件,我们在这个默认的settings.xml文件中也添加了一个JAVA8_HOME的变量后,编译就通过了,这就说明,maven编译的时候找的不是我在idea中配置的我自定义的settings.xml,而是先找的它默认的那个。因为里面没有,所以之前找不到JAVA8_HOME,导致编译失败、

总结:maven编译的时候应该是先找的默认的settings.xml,如果找不到,才会去找我在idea的settings选项下配置的“User settings file”中配置的settings.xml文件。

解决办法:删掉maven默认的去找的那个settings.xml文件,这样自定义的文件就会生效了

阅读全文
0 0