maven依赖冲突

一、短路优先
1、基本原则
A->B->C->X(jar)
A->B->X(jar)
这里会选择第2条路径
2、实例
nage依赖于bge,shanji依赖于nage
bge:
   < modelVersion > 4.0.0 </ modelVersion >
 
   < groupId > com.hongxing </ groupId >
   < artifactId > hongxing - bge </ artifactId >
   < version > 0.0.1-SNAPSHOT </ version >
   < packaging > jar </ packaging >
 
   < name > hongxing - bge </ name >
   < url > http://maven.apache.org </ url >
 
   < properties >
     < project.build.sourceEncoding > UTF-8 </ project.build.sourceEncoding >
   </ properties >
 
   < dependencies >
     < dependency >
       < groupId > junit </ groupId >
       < artifactId > junit </ artifactId >
       < version > 3.8.1 </ version >
       < scope > test </ scope >
     </ dependency >
     < dependency >
        < groupId > commons- io </ groupId >
        < artifactId > commons- io </ artifactId >
        < version > 2.4 </ version >
        </ dependency >
   </ dependencies >
</ project >
nage:
   < modelVersion > 4.0.0 </ modelVersion >
 
   < groupId > com.hongxing </ groupId >
   < artifactId > hongxing - nage </ artifactId >
   < version > 0.0.1-SNAPSHOT </ version >
   < packaging > jar </ packaging >
 
   < name > hongxing - nage </ name >
   < url > http://maven.apache.org </ url >
 
   < properties >
     < project.build.sourceEncoding > UTF-8 </ project.build.sourceEncoding >
   </ properties >
 
   < dependencies >
     < dependency >
       < groupId > junit </ groupId >
       < artifactId > junit </ artifactId >
       < version > 3.8.1 </ version >
       < scope > test </ scope >
     </ dependency >
     < dependency >
        < groupId > commons- io </ groupId >
        < artifactId > commons- io </ artifactId >
        < version > 2.0 </ version >
        </ dependency >
      < dependency >
               < groupId > com.hongxing </ groupId >
               < artifactId > hongxing - bge </ artifactId >
               < version > 0.0.1-SNAPSHOT </ version >
     </ dependency >
   </ dependencies >
</ project >
shanji:
   < modelVersion > 4.0.0 </ modelVersion >
 
   < groupId > com.hongxing </ groupId >
   < artifactId > hongxing - shanji </ artifactId >
   < version > 0.0.1-SNAPSHOT </ version >
   < packaging > jar </ packaging >
 
   < name > hongxing - shanji </ name >
   < url > http://maven.apache.org </ url >
 
   < properties >
     < project.build.sourceEncoding > UTF-8 </ project.build.sourceEncoding >
   </ properties >
 
   < dependencies >
     < dependency >
       < groupId > junit </ groupId >
       < artifactId > junit </ artifactId >
       < version > 3.8.1 </ version >
       < scope > test </ scope >
     </ dependency >
     < dependency >
        < groupId > com.hongxing </ groupId >
        < artifactId > hongxing - nage </ artifactId >
        < version > 0.0.1-SNAPSHOT </ version >
     </ dependency >
   </ dependencies >
</ project >
此时shanji依赖于2.0版本
19.png
 
二 路径相同,先声明先优先
shanji依赖于bge,shanji依赖于nage,bge和nage没有关系
bge:
   < modelVersion > 4.0.0 </ modelVersion >
 
   < groupId > com.hongxing </ groupId >
   < artifactId > hongxing - bge </ artifactId >
   < version > 0.0.1-SNAPSHOT </ version >
   < packaging > jar </ packaging >
 
   < name > hongxing - bge </ name >
   < url > http://maven.apache.org </ url >
 
   < properties >
     < project.build.sourceEncoding > UTF-8 </ project.build.sourceEncoding >
   </ properties >
 
   < dependencies >
     < dependency >
       < groupId > junit </ groupId >
       < artifactId > junit </ artifactId >
       < version > 3.8.1 </ version >
       < scope > test </ scope >
     </ dependency >
     < dependency >
        < groupId > commons- io </ groupId >
        < artifactId > commons- io </ artifactId >
        < version > 2.4 </ version >
        </ dependency >
   </ dependencies >
</ project >
nage:
   < modelVersion > 4.0.0 </ modelVersion >
 
   < groupId > com.hongxing </ groupId >
   < artifactId > hongxing - nage </ artifactId >
   < version > 0.0.1-SNAPSHOT </ version >
   < packaging > jar </ packaging >
 
   < name > hongxing - nage </ name >
   < url > http://maven.apache.org </ url >
 
   < properties >
     < project.build.sourceEncoding > UTF-8 </ project.build.sourceEncoding >
   </ properties >
 
   < dependencies >
     < dependency >
       < groupId > junit </ groupId >
       < artifactId > junit </ artifactId >
       < version > 3.8.1 </ version >
       < scope > test </ scope >
     </ dependency >
     < dependency >
        < groupId > commons- io </ groupId >
        < artifactId > commons- io </ artifactId >
        < version > 2.0 </ version >
        </ dependency >
   </ dependencies >
</ project >
shanji:
   < modelVersion > 4.0.0 </ modelVersion >
 
   < groupId > com.hongxing </ groupId >
   < artifactId > hongxing - shanji </ artifactId >
   < version > 0.0.1-SNAPSHOT </ version >
   < packaging > jar </ packaging >
 
   < name > hongxing - shanji </ name >
   < url > http://maven.apache.org </ url >
 
   < properties >
     < project.build.sourceEncoding > UTF-8 </ project.build.sourceEncoding >
   </ properties >
 
   < dependencies >
     < dependency >
       < groupId > junit </ groupId >
       < artifactId > junit </ artifactId >
       < version > 3.8.1 </ version >
       < scope > test </ scope >
     </ dependency >
     < dependency >
               < groupId > com.hongxing </ groupId >
               < artifactId > hongxing - bge </ artifactId >
               < version > 0.0.1-SNAPSHOT </ version >
        </ dependency >
     < dependency >
        < groupId > com.hongxing </ groupId >
               < artifactId > hongxing - nage </ artifactId >
               < version > 0.0.1-SNAPSHOT </ version >
         </ dependency >
       
   </ dependencies >
</ project >
此时shanji依赖于2.4版本


 
  • 大小: 11.9 KB
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值