maven项目之misconfigured toolchains问题

背景

在进行一个maven项目package和install的时候,出现一个报错,提示Misconifgured Toolchains

解决过程

maven在pom文件中配置具体使用toolchains:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>1.8</version>
<vendor>oracle</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>

涉及toolchains的地方有两个:

  • ${user.home}/.m2/toolchains.xml
  • ${maven.home}/conf/toolchains.xml

内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>1.6</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/path/to/jdk/1.6</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>1.8</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/path/to/jdk/1.8</jdkHome>
</configuration>
</toolchain>
</toolchains>

所以需要确认如上这几个地方内容即可。

根据官方说明:

idea中:

  • 会先判断${user.home}/.m2/toolchains.xml中的配置,
  • 找不到该文件的话,就再找${maven.home}/conf/toolchains.xml中的配置,
  • 如果都没有那么就异常了。

Actually, we can only specify the toolchains.xml in ${user.home}/.m2/toolchains.xml.

However, like for the settings.xml, it would be very convenient to specify a default toolchains.xml in ${maven.home}/conf/toolchains.xml

The idea is : If there is NO ${user.home}/.m2/toolchains.xml,
then uses ${maven.home}/conf/toolchains.xml,
otherwise NONE defined.

https://issues.apache.org/jira/browse/MNG-3891