Maven - 使用生成配置文件排除特定依赖项



基于 JDK11 对tools.jar的重组,我试图将其从 POM 依赖项中排除,如下所示

<profile>
<id>exclude-if-jdk11</id>
<activation>
<jdk>11</jdk>
</activation>
<properties>
<!-- bla bla bla -->
</properties>
<dependencies>
<dependency>
<groupId>com.internal.mypomz</groupId>
<artifactId>mypomext</artifactId>
<type>pom</type>
<version>1.1</version>
<exclusions>
<exclusion>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</profile>  

尽管如此,我还是收到错误,即.jar 工具JDK11/bin文件夹中找不到。但我期待这个罐子查找会被跳过。是不是我配置不正确?

经过一番挖掘,我们发现存在一种战争依赖,它也在获取tools.jar。所以是的,修复程序是使用mvn dependency:tree首先我们检查谁在取罐子。然后单独排除它们,直到mvn dependency:tree没有证据表明这一点。

我们让它同时适用于JDK11和JDK8。此外,作为问题中发布的profile正文的更新,我们现在已从 POM 中排除了所有tools.jar,并且更易于管理。

最新更新