在父pom的依赖管理中定义的传递依赖

时间:2015-03-05 17:17:17

标签: maven dependency-management transitive-dependency

'Dependency1'传递性地提取'dependency2',我想在我的项目中管理'dependency2'版本。

如果我在父pom中的依赖关系管理部分中只有'dependency1'和'dependency2',并且项目中只有'dependency1'子pom,那么项目将引入什么版本的'dependency2'?

类似的东西:

ParentPOM

<dependencyManagement>
  <dependencies>

        <dependency>
          <groupId> groupId </<groupId>
          <artifactId> artifact1 </artifactId>
          <version> version1 </version>
        </dependency>

        <dependency>
          <groupId> groupId </<groupId>
          <artifactId> artifact2 </artifactId>
          <version> version2 </version>
        </dependency>

  <dependencies>
<dependencyManagement>

ChildPOM

<dependencies>
   <dependency>
       <groupId> groupId1 </<groupId>
          <artifactId> artifact1 </artifactId>
          <version> version1 </version>
       </dependency>
  <dependencies>

1 个答案:

答案 0 :(得分:1)

您必须从重新定义的工件中排除传递依赖。

父pom.xml:

<dependencyManagement>
  <dependencies>

        <dependency>
          <groupId> groupId </<groupId>
          <artifactId> artifact1 </artifactId>
          <version>artifact1</version>
        </dependency>

        <dependency>
          <groupId> groupId </<groupId>
          <artifactId> artifact2 </artifactId>
          <version> version2 </version>
        </dependency>

  <dependencies>
<dependencyManagement>

Child pom.xml:

<dependencies>
   <dependency>
       <groupId> groupId1 </<groupId>
          <artifactId> artifact1 </artifactId>
          <version> version1 </version>
          <exclusions>
            <exclude>
              <groupId>groupId</groupId>
              <artifactId>artifact2</artifactId>
            </exclude>
          </exclusions>
       </dependency>
  <dependencies>