当引用相同工件的冲突版本时,如何使Maven失败? [英] How do I get Maven to fail when conflicting versions of the same artifact are referenced?
本文介绍了当引用相同工件的冲突版本时,如何使Maven失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果在依赖关系树中使用不同版本引用相同的工件,我希望Maven构建会失败.这似乎是一个相当琐碎的选择,但是我不知道该怎么做.有任何线索吗?
I'd like my Maven build to fail if the same artifact is referenced with different versions in my dependency tree. This would seem like a fairly trivial option, but I can't work out how to do it. Any clues?
推荐答案
maven-enforcer-plugin具有 dependencyConvergence 规则可以满足您的需求.这是文档中的示例.
The maven-enforcer-plugin has a dependencyConvergence rule which does what you want. Here's an example from the documentation.
这将导致构建失败:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>
在编译过程中将其记录下来:
With this being logged during compilation:
[ERROR]
Dependency convergence error for org.slf4j:slf4j-api:1.6.1 paths to dependency are:
+-org.myorg:my-project:1.0.0-SNAPSHOT
+-org.slf4j:slf4j-jdk14:1.6.1
+-org.slf4j:slf4j-api:1.6.1
and
+-org.myorg:my-project:1.0.0-SNAPSHOT
+-org.slf4j:slf4j-nop:1.6.0
+-org.slf4j:slf4j-api:1.6.0
这篇关于当引用相同工件的冲突版本时,如何使Maven失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文