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版本


 

猜你喜欢

转载自cakin24.iteye.com/blog/2393471