Maven解决依赖冲突

依赖冲突

若项目中多个Jar同时引用了相同的Jar时,会产生依赖冲突,但Maven采用了两种避免冲突的策略,因此在Maven中是不存在依赖冲突的。

  • 短路优先
  1. 本项目——>A.jar——>B.jar——>X.jar

  2. 本项目——>C.jar——>X.jar

若本项目引用了A.jar,A.jar又引用了B.jar,B.jar又引用了X.jar,并且C.jar也引用了X.jar。

在此时,Maven只会引用引用路径最短的Jar。

  • 声明优先

    若引用路径长度相同时,在pom.xml中谁先被声明,就使用谁。

或者直接写死:

The maven way of resolving situations like this is to include a <dependencyManagement> section in your project's root pom, where you specify which version of which library will be used.

<dependencyManagement>

  <dependencies>
    <dependency>
        <groupId>foo</groupId>
        <artifactId>bar</artifactId>
        <version>1.2.3</version>
    </dependency>
   </dependencies>
</dependencyManagement>

posted on 2020-03-23 00:10  卖肾割阑尾  阅读(109)  评论(0编辑  收藏  举报

导航