<exclusions>
可以通过在 a 中声明一个元素来排除依赖项中的工件,<dependency>
但在这种情况下,需要排除从父项目继承的工件。正在讨论的 POM 摘录如下:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>jruby</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>ALL-DEPS</artifactId>
<version>1.0</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
</dependencies>
</project>
base
artifact,取决于 javax.mail:mail-1.4.jar
,并且ALL-DEPS
依赖于同一库的另一个版本。由于mail.jar
fromALL-DEPS
存在于执行环境中,虽然没有导出,但与mail.jar
父级上存在的相冲突,其范围为compile
.
一个解决方案可能是从父 POM 中删除 mail.jar,但是大多数继承 base 的项目都需要它(就像 log4j 的传递依赖项一样)。所以我想做的是简单地从子项目中排除父库base
,因为如果是依赖项而不是父 pom ,则可以这样做:
...
<dependency>
<artifactId>base</artifactId>
<groupId>es.uniovi.innova</groupId>
<version>1.0.0</version>
<type>pom<type>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
</exclusions>
</dependency>
...