Maven:当前项目和依赖项目使用相同库的不同版本

时间:2016-08-31 16:37:53

标签: java maven hadoop

我的主项目的pom声明了hadoop-client的版本。依赖项声明hadoop-client的不同版本。实际上最终会使用哪一个?

我的主要项目的pom.xml:

<dependency>
   <groupId>com.apache.hadoop</groupId>
   <artifactId>hadoop-client</artifactId>
   <version>2.7.0</version>
   <exclusions>
       <exclusion>
           <groupId>*</groupId>
           <artifactId>*</artifactId>
       </exclusion>
   </exclusions>
</dependency>
<dependency>
   <groupId>com.myown.group</groupId>
   <artifactId>my-own-artifact</artifactId>
   <version>1.0.0</version>
   <exclusions>
       <exclusion>
           <groupId>*</groupId>
           <artifactId>*</artifactId>
       </exclusion>
   </exclusions>
</dependency>

我的主要项目依赖的库的pom.xml:

<dependency>
       <groupId>com.apache.hadoop</groupId>
       <artifactId>hadoop-client</artifactId>
       <version>2.5.0</version>
       <exclusions>
           <exclusion>
               <groupId>*</groupId>
               <artifactId>*</artifactId>
           </exclusion>
       </exclusions>
    </dependency>
<dependency>

1 个答案:

答案 0 :(得分:3)

Maven has a complex set of rules for version resolution, summarized as 'nearest wins'. One source of details is this post here. You can find out what Maven decided by using mvn dependency:list or mvn dependency:tree.