1. 程式人生 > >針對Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解決方案

針對Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解決方案

failed led tool data- rdquo xml文件 artifact 裏的 span

背景:本項目使用JDK1.8

編譯maven工程的時候出現如下錯誤:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1

pom中如下配置maven插件,配置中聲明使用JDK1.8:

[html] view plain copy
  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-compiler-plugin</artifactId>
  4. <version>3.1</version>
  5. <configuration>
  6. <verbose>true</verbose>
  7. <fork>true</fork>
  8. <executable>${JAVA8_HOME}/bin/javac</executable>
  9. </configuration>
  10. </plugin>

這裏的${JAVA8_HOME}這個變量是在settings.xml中配置的,如下:

[html] view plain copy
  1. <profile>
  2. <id>custom-compiler</id>
  3. <properties>
  4. <JAVA8_HOME>C:\Program Files (x86)\Java\jdk1.8.0_73</JAVA8_HOME>
  5. </properties>
  6. </profile>

當然這裏應該需要激活,所以settings.xml文件還應該有如下配置:

[html] view plain copy
  1. <activeProfiles>
  2. <activeProfile>custom-compiler</activeProfile>
  3. </activeProfiles>

從pom文件中CTRL點擊變量JAVA8_HOME能跳到settings.xml中找到它的定義處,按理來說應該是能找到這個變量,出現上述問題並不是因為找不到這個變量。我將pom文件中的JAVA8_HOME這個變量直接用實際的路徑替換,即替換為

[html] view plain copy
  1. 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文件,這樣自定義的文件就會生效了

針對Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1的解決方案