无论如何要排除从父 POM 继承的工件? [英] Is there anyway to exclude artifacts inherited from a parent POM?
问题描述
依赖项中的工件可以通过在
中声明一个
元素来排除,但在这种情况下,需要排除从父项目.正在讨论的 POM 摘录如下:
Artifacts from dependencies can be excluded by declaring an <exclusions>
element inside a <dependency>
But in this case it's needed to exclude an artifact inherited from a parent project. An excerpt of the POM under discussion follows:
<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
依赖于相同的另一个版本图书馆.由于ALL-DEPS
中的mail.jar
存在于执行环境中,虽然没有导出,但与mail.jar
冲突存在于父级上,其作用域为 compile
.
base
artifact, depends on javax.mail:mail-1.4.jar
, and ALL-DEPS
depends on another version of the same library. Due to the fact that mail.jar
from ALL-DEPS
exist on the execution environment, although not exported, collides with the mail.jar
that exists on the parent, which is scoped as compile
.
一个解决方案可能是从父 POM 中删除 mail.jar,但大多数继承 base 的项目都需要它(就像 log4j 的传递依赖项).所以我想做的是简单地从子项目中排除父级的库,因为如果 base
是一个依赖项而不是父 pom 就可以做到:>
A solution could be to rid off mail.jar from the parent POM, but most of the projects that inherit base, need it (as is a transtive dependency for log4j). So What I would like to do is to simply exclude parent's library from the child project, as it could be done if base
was a dependency and not the parent 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>
...
推荐答案
一些想法:
在这种情况下,也许您不能简单地从父级继承(并声明对
base
的依赖并排除).如果父 pom 中有很多东西,那就不太方便了.
Maybe you could simply not inherit from the parent in that case (and declare a dependency on
base
with the exclusion). Not handy if you have lot of stuff in the parent pom.
另一件要测试的事情是在 dependencyManagement
下用 ALL-DEPS
所需的版本声明 mail
工件父 pom 强制收敛(虽然我不确定这是否会解决范围问题).
Another thing to test would be to declare the mail
artifact with the version required by ALL-DEPS
under the dependencyManagement
in the parent pom to force the convergence (although I'm not sure this will solve the scoping problem).
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>???</version><!-- put the "right" version here -->
</dependency>
</dependencies>
</dependencyManagement>
- 或者,如果您不使用依赖它的功能,您可以从 log4j 中排除
mail
依赖项(这就是我要做的):
- Or you could exclude the
mail
dependency from log4j if you're not using the features relying on it (and this is what I would do):
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
- 或者你可以恢复到 log4j 的 1.2.14 版本而不是异端的 1.2.15 版本(他们为什么不将上述依赖项标记为可选?!).
这篇关于无论如何要排除从父 POM 继承的工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!