Maven - 检测相同依赖关系的多个版本 [英] Maven - Detect Multiple Versions of the Same Dependency

查看:891
本文介绍了Maven - 检测相同依赖关系的多个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到了我的maven项目的两个直接依赖项的情况,它有两个不同版本的特定传递依赖。

I just experienced a case of two direct dependencies of my maven project having two different versions of a particular transitive dependency.

在我的特定情况下,我有直接的依赖关系以下内容:

In my particular case I had direct dependencies on the following:

    <dependency>
        <groupId>org.jclouds.driver</groupId>
        <artifactId>jclouds-sshj</artifactId>
        <version>${jclouds.version}</version>
    </dependency>

    <dependency>
        <groupId>org.mule.modules</groupId>
        <artifactId>mule-module-jersey</artifactId>
        <version>${mule.version}</version>
    </dependency>

这两个依赖关系都对com.sun.jersey有一个(深层)传递依赖:jersey-core ,但每个版本都有不同的版本。 Maven没有对此失败,甚至发出警告(或者如果确实如此,我从未见过它!)这样的事情正在发生......因此我在调试发动机版本时发生的问题之前从未注意到它 - 由jclouds依赖带来的核心导致一些事情破裂。

Both of these dependencies had a (deep) transitive dependency on com.sun.jersey:jersey-core, but with different versions for each. Maven didn't fail on this or even warn (or if it did, I never saw it!) that such a thing was happening... and as such I never noticed it until debugging a problem that happened when the version of jersey-core brought in by the jclouds dependency caused some things to break.

是否存在maven插件或其他一些工具,可以检测到这种深度传递依赖性覆盖并至少警告用户(或者maven执行失败)它会检测到这样的冲突...即使默认的maven行为只是选择解析依赖项时出现的第一个版本?

Is there a maven plugin or some other tool that exists that will detect this sort of deep transitive dependency overriding and at least warn the user (or fail the maven execution) if it detects such a collision... even if the default maven behavior is to just pick the first version that appears when resolving dependencies?

推荐答案

使用Dependency Enforcer插件。当依赖关系无法正确收敛时,它将停止构建。

Use the Dependency Enforcer plugin. It will stop the build when dependencies don't converge properly.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.0.1</version>
    <executions>
      <execution>
        <id>enforce</id>
        <configuration>
          <rules>
            <DependencyConvergence />
          </rules>
        </configuration>
        <goals>
          <goal>enforce</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

这篇关于Maven - 检测相同依赖关系的多个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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