在 Maven 中如何解决为什么选择了错误版本的工件?
In maven how to troubleshoot why wrong version of artifact was picked-up?
我正在使用 Maven 来构建项目。
它使用了一些库 A
,后者又使用了库 B_v2
.
但是,当我执行 mvn dependency:tree
时,我看到使用了库 B v1
。我不希望这种情况发生,因为现在我 运行 我有一个从未测试过的 lib A
+ B_v1
的组合。
显然这是因为在解析 lib 版本并使用 B_v1
时,另一个工件获胜。
我想知道使用哪个神器 "won" 并强制使用 B_v1
(这样我就可以修复这个神器以也使用 B_v2
)
它一定是 mvn dependency:tree
的文物之一,但那里有很多。
这是Maven用于依赖解析的策略,如Introduction to the Dependency Mechanism所述:
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven picks the "nearest definition". That is, it uses the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, the first declaration wins.
- "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies. For example, if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0.
默认mvn dependency:tree
不列出因版本冲突而省略的依赖,所以只要B
在[中有相同的groupId
和artifactId
=14=]和v2
,它应该只出现一次:神器"won"。 (您可以看到所有省略的依赖项,使用 mvn dependency:tree -Dverbose
标记为这样。)
我正在使用 Maven 来构建项目。
它使用了一些库 A
,后者又使用了库 B_v2
.
但是,当我执行 mvn dependency:tree
时,我看到使用了库 B v1
。我不希望这种情况发生,因为现在我 运行 我有一个从未测试过的 lib A
+ B_v1
的组合。
显然这是因为在解析 lib 版本并使用 B_v1
时,另一个工件获胜。
我想知道使用哪个神器 "won" 并强制使用 B_v1
(这样我就可以修复这个神器以也使用 B_v2
)
它一定是 mvn dependency:tree
的文物之一,但那里有很多。
这是Maven用于依赖解析的策略,如Introduction to the Dependency Mechanism所述:
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven picks the "nearest definition". That is, it uses the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, the first declaration wins.
- "nearest definition" means that the version used will be the closest one to your project in the tree of dependencies. For example, if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0.
默认mvn dependency:tree
不列出因版本冲突而省略的依赖,所以只要B
在[中有相同的groupId
和artifactId
=14=]和v2
,它应该只出现一次:神器"won"。 (您可以看到所有省略的依赖项,使用 mvn dependency:tree -Dverbose
标记为这样。)