gpt4 book ai didi

java - 如何在依赖管理和传递依赖之间获取 "conflicts"的 Maven 依赖收敛报告?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:04:06 25 4
gpt4 key购买 nike

我正在寻找一种方法来获得一种依赖收敛报告,该报告列出了在 dependency-management 中定义但被不同版本的传递依赖引用的依赖。

我知道maven-project-info-reports-plugin:dependency-convergence ,但此列表仅列出了 dependency 中定义的依赖项(和传递依赖项)之间的冲突,但是一旦我在 dependency-management 中定义了该依赖项,它就不会列出在报告中。

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


背景:

我有一个 Maven 多模块项目:

  • 以前我没有使用过depencency-managent,但是我使用属性在父pom中定义依赖版本,并在每个模块的dependency部分声明依赖,具有该属性。
  • 但后来我想,让我们遵循 Maven 最佳实践并在父项目 depencency-managent 中声明依赖项和版本,并从子项目 depencency 中删除版本标签s.

(以前)我使用 maven-project-info-reports-plugin:dependency-convergence 报告来发现具有版本冲突的传递依赖项。为了决定我可以“忽略”那个冲突,或者我必须做些什么来解决它。 (通常我“忽略”错误修复级别(版本号增量 0.0.X)的冲突,但花更多时间在主要或次要更改级别的冲突上。

但是在我将依赖项移动到 depencency-managent 之后,maven-project-info-reports-plugin:dependency-convergence 报告几乎是空的并且没有发现任何问题。

最佳答案

带有额外 Enforcer 规则的 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在某些情况下可能会发生。但是不要太麻烦,基本上它很好用。

关于java - 如何在依赖管理和传递依赖之间获取 "conflicts"的 Maven 依赖收敛报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42386693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com