父项中的dependencyManagement被忽略 [英] dependencyManagement in parent ignored

查看:112
本文介绍了父项中的dependencyManagement被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建罐子的项目P1.该项目有一个父POM P1-PARENT. P1-父母包括以下内容:

I have a project, P1, that creates a jar. That project has a parent POM, P1-PARENT. P1-Parent includes the following:

<dependencyManagement>
    <!-- Kafka uses Zookeeper 3.3.4, but Curator requires 3.4.5. To resolve
         we specify 3.4.5 so all projects using either Kafka or Curator will
         get the later version which is compatible with both projects. -->
    <dependency>
      <groupId>org.apache.zookeeper</groupId>
      <artifactId>zookeeper</artifactId>
      <version>3.4.5</version>
    </dependency>
    <dependency>
      <groupId>org.apache.kafka</groupId>
      <artifactId>kafka_2.10</artifactId>
      <version>0.8.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.curator</groupId>
      <artifactId>curator-client</artifactId>
      <version>2.2.0-incubating</version>
    </dependency>
    <!-- A bunch of other irrelevant stuff here -->
</dependencyManagement>

这有效-"mvndependency:tree"的输出包括:

This works - the output of "mvn dependency:tree" includes:

[INFO] +- org.apache.kafka:kafka_2.10:jar:0.8.0:compile
[INFO] |  +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile (version managed from 3.3.4)

请注意,这是对Zookeeper的唯一依赖项(已通过"mvndependency:tree | grep zoo"验证.

Note that this is the only dependency on zookeeper (verified via "mvn dependency:tree | grep zoo".

我还有几个其他项目也继承自P1-PARENT,并且一切正常,它们都加入了ZooKeeper 3.4.5.但是,我的一个同事最近开始在他们的一个项目中使用P1.他们的项目不是从P1-PARENT继承的.他们从P1获得的传递依赖是ZooKeeper 3.3.4,而不是3.4.5.我们已经通过"mvndependency:tree"验证了他们将zookeeper.3.3.4作为Kafka的传递依赖项(例如,输出看起来与我上面粘贴的内容相同,但是版本为3.3.4,但它没有同样,像我的项目一样,它们对ZooKeeper的唯一依赖关系(可传递或其他方式)是通过P1(已通过dependency:tree和grep验证).问题是, 为什么.当它们包含P1时,在确定P1的传递依存关系时是否应该先看一下P1的父POM?

I have several other projects that also inherit from P1-PARENT and everything works fine, they all pull in ZooKeeper 3.4.5. However, A coworker of mine recently starting using P1 in one of their projects. Their project doesn't inherit from P1-PARENT. The transitive dependency they get from P1 is ZooKeeper 3.3.4, not 3.4.5. We have verified, via "mvn dependency:tree", that they get zookeeper.3.3.4 as a transitive dependency of Kafka (e.g. the output looks identical to what I've pasted above, but the version is 3.3.4 and it doesn't include the "(version managed ..." bit). Also, like my projects, the only dependency they have on ZooKeeper (transitive or otherwise) is through P1 (verified by dependency:tree and grep). The question is, why. When they include P1, shouldn't maven look at P1's parent POM when determining the transitive dependencies of P1?

我正在使用Maven 3.0.5.他们正在使用3.0.3和3.1.1版本,并看到了这两个版本的问题.

I'm using Maven 3.0.5. They're using versions 3.0.3 and 3.1.1 and see the problem with both of those versions.

推荐答案

在这种情况下,Maven无法解决版本传递依赖项问题.

Maven doesn't resolve the version transitive dependency issue in this case.

可以通过使用maven bom概念来解决此问题.

This issue can be used by using maven bom concept.

在下面的链接中查看Maven文档中的Bom http://maven.apache.org/guides/introduction /introduction-to-dependency-mechanism.html#Dependency_Management

Check the maven documentation for bom in the below link http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management

这是另一个博客,介绍了bom的用法 http://howtodoinjava.com/maven/maven-bom-bill-材料依赖/

Here is another blog which explains usage of bom's http://howtodoinjava.com/maven/maven-bom-bill-of-materials-dependency/

要解决此问题,您需要在面临该问题的其他项目的dependencyManagement部分中添加父pom的依赖项.

In your case to solve this issue, you need to add a dependency of your parent pom in the dependencyManagement section of other project where you are facing the issue.

这篇关于父项中的dependencyManagement被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆