0

我只是想maven-enforcer-plugin用一个小的 pom 来获取(在我进入我的项目 pom 之前,它有 100 多个依赖项。)
在我添加了执行器插件之后,我看到了Dependency convergence error. pom.xml文件在下面(抱歉它不整洁)
。 如何在不禁用强制插件的情况下修复错误。 基本上我想了解如何使用规则背后的概念。
dependencyConvergence

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo</groupId>
    <artifactId>enforcer</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencyManagement>
        <dependencies>
            <!-- 
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>5.2.13.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aop</artifactId>
                <version>5.2.13.RELEASE</version>
            </dependency>
            -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>5.2.10.RELEASE</version>
            </dependency> 
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>5.4.5</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>3.0.0-M3</version>
                <executions>
                    <execution>
                        <id>dependency-convergence</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <dependencyConvergence/>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <rules>
                        <dependencyConvergence />
                    </rules>
                </configuration>
            </plugin>
        </plugins>

    </build>

</project>

这是否意味着,我必须在此版本的pom.xml中显式声明dependencyManagement 中的每个非收敛依赖项(将依赖项添加到dependencyManagement)。
问题spring-context 仍然存在,因为我已将其添加为直接依赖项,然后在具有不同版本的依赖项管理中。

基本上 - 能够修复错误,但还不能清楚地掌握规则。

  1. 修复一个 - pom.xml - 将依赖管理中的版本更新为明确使用的版本。所以现在不需要在依赖项中明确给出版本。但这需要我能够访问父 pom 的dependencyManagment。如果我的说法是正确的,那么情况可能并非每次都如此。

  2. 修复两个pom.xml - 从 spring-security-web 中排除 spring-context 并且它有效。但是,如果要进行十几个排除,那将是一件痛苦的事情。

如果这是采用收敛规则的方法?在具有 100 多个依赖项和 100 多个传递依赖项的企业项目中,物料清单 (BOM) 将非常庞大并且需要时间来构建。嗯。(我同意,对使用的版本和使用 <xyz.version> 之类的属性会有更多的控制,升级可以轻松完成)。

如果有人能列出涉及收敛的规则,我将不胜感激。

4

1 回答 1

1

依赖收敛错误意味着

  • 依赖项不在 dependencyManagement 中
  • 依赖树中有不同版本的依赖

典型的解决方法是在dependencyManagement 中定义一个条目来解决问题,或者在dependencyManagement 中定义import一个适当的BOM。

这最好在多模块项目的主 POM 中完成,但也可以在模块中完成。

请注意,最好省略该部分中的<version>标记,<dependencies>以便在任何地方都使用dependencyManagement。

于 2021-11-05T12:04:10.823 回答