maven 相关收敛误差

t3psigkw  于 2023-11-17  发布在  Maven
关注(0)|答案(3)|浏览(105)

更新Firefox后,我将库的版本更改为更高的版本。出现以下错误:[ERROR] Dependency convergence error for commons-collections:commons-collections:3.2.2 dependency的路径是:

[ERROR] +-net:serenity.pom.gradle:0.0.1-SNAPSHOT
[ERROR] +-net.serenity-bdd:serenity-core:1.1.29-rc.3
[ERROR] +-org.seleniumhq.selenium:htmlunit-driver:2.20
[ERROR] +-commons-collections:commons-collections:3.2.2
[ERROR] and
[ERROR] +-net:serenity.pom.gradle:0.0.1-SNAPSHOT
[ERROR] +-net.serenity-bdd:serenity-core:1.1.29-rc.3
[ERROR] +-io.appium:java-client:3.3.0
[ERROR] +-commons-validator:commons-validator:1.4.1
[ERROR] +-commons-collections:commons-collections:3.2.1
[ERROR] and
[ERROR] +-net:serenity.pom.gradle:0.0.1-SNAPSHOT
[ERROR] +-net.serenity-bdd:serenity-core:1.1.29-rc.3
[ERROR] +-commons-collections:commons-collections:3.2.2
[ERROR] ]
[ERROR] -> [Help 1]

字符串
依赖树看起来像:

[INFO] +- net.serenity-bdd:serenity-core:jar:1.1.29-rc.3:test
[INFO] |  +- org.seleniumhq.selenium:htmlunit-driver:jar:2.20:test
[INFO] |  +- commons-collections:commons-collections:jar:3.2.2:test
[INFO] |  +- io.appium:java-client:jar:3.3.0:test
[INFO] |  |  \- commons-validator:commons-validator:jar:1.4.1:test
[INFO] |  |     +- commons-beanutils:commons-beanutils:jar:1.8.3:test
[INFO] |  |     \- commons-digester:commons-digester:jar:1.8.1:test


如何解决这个问题?我可以手动切换库吗?
PS这里是我的pom.xml

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>1.1.29-rc.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-jbehave</artifactId>
        <version>1.9.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.2.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <id>verify</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>enforce</goal>
                    </goals>
                    <inherited>true</inherited>
                </execution>
            </executions>
            <configuration>
                <failFast>true</failFast>
                <rules>
                    <DependencyConvergence></DependencyConvergence>
                    <requireReleaseDeps>
                        <onlyWhenRelease>true</onlyWhenRelease>
                    </requireReleaseDeps>
                    <requireJavaVersion>
                        <version>${java.version}</version>
                    </requireJavaVersion>
                </rules>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.18</version>
            <configuration>
                <includes>
                    <include>src/test/java/*.java </include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>net.serenity-bdd.maven.plugins</groupId>
            <artifactId>serenity-maven-plugin</artifactId>
            <version>1.1.29-rc.1</version>
            <dependencies>
                <dependency>
                    <groupId>net.serenity-bdd</groupId>
                    <artifactId>serenity-core</artifactId>
                    <version>1.1.29-rc.3</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>serenity-reports</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

b1payxdu

b1payxdu1#

参见POM参考,排除:
排除显式地告诉Maven您不想包含作为此依赖项的依赖项(换句话说,它的传递依赖项)的指定项目。
参见Apache Maven Enforcer Rules, Dependency Convergence
如果一个项目有两个依赖项A和B,它们都依赖于同一个工件C,那么如果A依赖的C版本与B依赖的C版本不同,则此规则将导致构建失败。
[...]
一定会成功的。

<dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <version>1.6.1</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-nop</artifactId>
      <version>1.6.0</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

字符串

g6ll5ycj

g6ll5ycj2#

我知道我迟到了,但是在挠头了8-10个小时之后,我想出了这个解决方案,它解决了当你无法控制不同的pom时的问题,其中不同版本的依赖项在不同的地方使用。所以,我认为值得分享。
@格罗尔德的回答是一个理想的答案(来源:Maven wiki)。但是,它适用于所有依赖项的所有者,并且有时间,奢侈和写权限从根本上解决问题的情况。在我的情况下,我使用的是公司范围内的全局父pom,它在不同的地方设置了不同的版本,所以我面临着这个问题。我想找到一些方法来解决这个问题,在我的结束,而不改变全局父pom。
要解决此问题,您可以在项目的父pom中指定与其余位置匹配的确切版本,并覆盖不同位置的全局父pom指定的版本。您可以在项目的父pom中添加此块

<!-- ============================= -->
<!-- DEPENDENCY MANAGEMENT -->
<!-- ============================= -->
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <!-- This version should be consistent 
                 with versions at other places -->
            <version>3.2.2</version>
        </dependency>
    </dependencies>
</dependencyManagement>

字符串
HTH

fkvaft9z

fkvaft9z3#

或者如果你真的/暂时需要解决这个问题,就一起删除maven enforcer。

相关问题