有人可以解释人们如何在战争中获得不同版本的重复依赖项吗?也许举一些例子
我无法理解我的生活。Maven2 具有传递依赖项的依赖中介
假设我有:
A
- B
- C
B
- E
现在在一个项目 X 中,使用 war 打包,我添加了 A 和 B 作为依赖项。
由于上述依赖中介,无论项目 A 中的 B 版本如何,在战争中我都会看到一个 B jar,其中声明的版本在 X 中。
这是因为 maven 将使用与我的项目最接近的依赖项的版本。
那么,我在这里错过了什么?人们怎么搞砸了?期待启蒙
对于具有相同 groupId 和 artifactID 的冲突 jar,maven 采用来自 finally 声明的依赖项的版本。
你可以玩依赖顺序。只需更改项目 X 中 A 和 B 的依赖顺序即可。
场景1:这里由于2.5是在2.3之后添加的,所以2.5将被打包。
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
场景2:这里由于2.3是在2.5之后添加的,2.3将被打包。
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
您也可以在此处尝试排除概念。