如何获取依赖管理和传递依赖之间“冲突”的Maven依赖性收敛报告?

时间:2017-02-22 08:52:33

标签: java maven dependency-management

我搜索了一种方法来获得一种依赖性收敛报告,该报告列出了dependency-management中定义的依赖关系,但是由具有不同版本的传递依赖关系引用。

我知道maven-project-info-reports-plugin:dependency-convergence,但这只列出dependency中定义的依赖关系(和传递依赖关系)之间的冲突,但是一旦我在dependency-management中定义了该依赖关系,它就会得到未列在报告中。

我只想要一份报告,如果发生这种“冲突”,我不想让构建失败。

背景:

我有一个Maven-Multi-Module项目:

  • 以前我没有使用depencency-managent,但是我使用属性来定义父pom中的依赖版本,并使用该属性在每个模块的dependency部分中声明了依赖项。
  • 但后来我想,让我们按照Maven的最佳做法,在父depencency-managent中声明依赖项和版本,并从子项目depencency中删除version-tag。

(以前)我使用maven-project-info-reports-plugin:dependency-convergence报告来发现版本冲突的传递依赖项。为了决定我可以“忽略”那个冲突,或者我必须做些什么来解决它。 (典型的我“忽略”了bugfix级别的冲突(版本号delta 0.0.X),但是花费更多的时间来处理主要或次要变化级别的冲突。

但在我将依赖项移至depencency-managent后,maven-project-info-reports-plugin:dependency-convergence报告几乎为空,并未发现任何问题。

1 个答案:

答案 0 :(得分:4)

带有额外执行规则的Maven Enforcer插件怎么样?

让我们在由我们管理的Selenium版本与PhantomJS使用的版本之间产生一点冲突:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>de.scrum-master.stackoverflow</groupId>
  <artifactId>dependency-convergence</artifactId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>
      <!-- Enforce important build rules -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
          <execution>
            <id>enforcer-rules-error</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <fail>false</fail>
              <skip>false</skip>
              <rules>
                <requireMavenVersion>
                  <version>3.2.5</version>
                </requireMavenVersion>
              </rules>
            </configuration>
          </execution>
          <execution>
            <id>enforcer-rules-warning</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <fail>false</fail>
              <skip>false</skip>
              <rules>
                <dependencyConvergence/>
              </rules>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>extra-enforcer-rules</artifactId>
            <version>1.0-beta-6</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.3.0</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.0.1</version>
        <scope>test</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>com.codeborne</groupId>
      <artifactId>phantomjsdriver</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

</project>

报告看起来像这样(你必须学习阅读):

[WARNING] 
Dependency convergence error for commons-codec:commons-codec:1.9 paths to dependency are:
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-remote-driver:2.53.0
      +-org.apache.httpcomponents:httpclient:4.5.1
        +-commons-codec:commons-codec:1.9
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-net.sourceforge.htmlunit:htmlunit:2.23
        +-commons-codec:commons-codec:1.10

[WARNING] 
Dependency convergence error for org.apache.httpcomponents:httpclient:4.5.1 paths to dependency are:
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-remote-driver:2.53.0
      +-org.apache.httpcomponents:httpclient:4.5.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-net.sourceforge.htmlunit:htmlunit:2.23
        +-org.apache.httpcomponents:httpclient:4.5.2
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-net.sourceforge.htmlunit:htmlunit:2.23
        +-org.apache.httpcomponents:httpmime:4.5.2
          +-org.apache.httpcomponents:httpclient:4.5.2

[WARNING] 
Dependency convergence error for org.seleniumhq.selenium:selenium-remote-driver:2.53.0 paths to dependency are:
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-remote-driver:2.53.0
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-chrome-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-edge-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-firefox-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-ie-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-opera-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-safari-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-support:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1

[WARNING] Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for commons-codec:commons-codec:1.9 paths to dependency are:
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-remote-driver:2.53.0
      +-org.apache.httpcomponents:httpclient:4.5.1
        +-commons-codec:commons-codec:1.9
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-net.sourceforge.htmlunit:htmlunit:2.23
        +-commons-codec:commons-codec:1.10
, 
Dependency convergence error for org.apache.httpcomponents:httpclient:4.5.1 paths to dependency are:
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-remote-driver:2.53.0
      +-org.apache.httpcomponents:httpclient:4.5.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-net.sourceforge.htmlunit:htmlunit:2.23
        +-org.apache.httpcomponents:httpclient:4.5.2
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-net.sourceforge.htmlunit:htmlunit:2.23
        +-org.apache.httpcomponents:httpmime:4.5.2
          +-org.apache.httpcomponents:httpclient:4.5.2
, 
Dependency convergence error for org.seleniumhq.selenium:selenium-remote-driver:2.53.0 paths to dependency are:
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-remote-driver:2.53.0
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-chrome-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-edge-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-firefox-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-ie-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-opera-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-safari-driver:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
and
+-de.scrum-master.stackoverflow:dependency-convergence:1.0-SNAPSHOT
  +-com.codeborne:phantomjsdriver:1.3.0
    +-org.seleniumhq.selenium:selenium-java:3.0.1
      +-org.seleniumhq.selenium:selenium-support:3.0.1
        +-org.seleniumhq.selenium:selenium-remote-driver:3.0.1
]

我希望这有助于实现您的目的。

警告:我发现这个strange little glitch在某些情况下会发生。但是,让它不要太麻烦你,基本上它很好用。