gpt4 book ai didi

maven - Maven中相同依赖项的多个版本

转载 作者:行者123 更新时间:2023-12-03 09:28:51 26 4
gpt4 key购买 nike

是否可以申报相同依赖项的多个版本 在 Maven 仓库中?
我一次需要这些依赖项:

    <dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.9-R0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.2-R0.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.6.4-R2.0</version>
<scope>compile</scope>
</dependency>
因为它们每个都包含我关心的不同包:

org.bukkit.craftbukkit.v1_6_R3

org.bukkit.craftbukkit.v1_7_R1

org.bukkit.craftbukkit.v1_7_R3


如果我如第一个片段所示声明依赖项,则只有最后一个会生效。有没有办法在 Maven 中实现这一点?
@Edit 任何解决方法,也许?

最佳答案

这是the Maven documentation的相关部分,它解释了当存在多种可能性时 Maven 如何选择依赖项的版本:

Dependency mediation - this determines what version of an artifactwill be chosen when multiple versions are encountered as dependencies.Maven picks the "nearest definition". That is, it uses the version ofthe closest dependency to your project in the tree of dependencies.You can always guarantee a version by declaring it explicitly in yourproject's POM. Note that if two dependency versions are at the samedepth in the dependency tree, the first declaration wins. "nearestdefinition" means that the version used will be the closest one toyour project in the tree of dependencies. Consider this tree ofdependencies:

A
├── B
│ └── C
│ └── D 2.0
└── E
└── D 1.0

In text, 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. Youcould explicitly add a dependency to D 2.0 in A to force the use of D2.0, as shown here:

A
├── B
│ └── C
│ └── D 2.0
├── E
│ └── D 1.0

└── D 2.0

关于maven - Maven中相同依赖项的多个版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24962607/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com