反正有没有排除从父POM继承的工件? [英] Is there anyway to exclude artifacts inherited from a parent POM?
问题描述
可以通过在< dependency>
中声明< exclusions>
元素来排除来自依赖项的工件。但是在这种情况下,需要排除从父项目继承的工件。正在讨论的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>提供< / scope>
< type> pom< / type>
< / dependency>
< / dependencies>
< / project>
base
工件,取决于 javax.mail:mail-1.4.jar
和 ALL-DEPS
取决于同一个库的另一个版本。由于执行环境中存在来自 ALL-DEPS
的 mail.jar
,尽管未导出,但与父元素上存在的 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>
...
一些想法:
-
在这种情况下,你可能根本不能继承父母(并且声明对
base <的依赖关系
除外)。如果父母pom中有很多东西,那就不方便了。 -
要测试的另一件事是声明
邮件
在父pom中的dependencyManagement
下的ALL-DEPS
所需版本的工件强制收敛(虽然我不确定这会解决范围问题)。
< dependencyManagement>
< dependencies>
< dependency>
< groupId> javax.mail< / groupId>
< artifactId> mail< / artifactId>
< version> ???< / version><! - 将正确版本放在此处 - >
< / dependency>
< / dependencies>
< / dependencyManagement>
- 或者你可以排除
邮件
来自log4j的依赖,如果你没有使用依赖它的功能(这就是我要做的):
< pre class =lang-xml prettyprint-override> < dependency>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.15< / version>
< scope>提供< / 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版本(为什么他们没有将上述依赖关系标记为可选?!)。
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, 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
.
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>
...
Some ideas:
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.Another thing to test would be to declare the
mail
artifact with the version required byALL-DEPS
under thedependencyManagement
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>
- 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>
- Or you could revert to the version 1.2.14 of log4j instead of the heretic 1.2.15 version (why didn't they mark the above dependencies as optional?!).
这篇关于反正有没有排除从父POM继承的工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!