为什么Maven会忽略测试依赖项中定义的编译传递依赖项的版本

时间:2019-01-03 12:30:57

标签: maven selenium serenity-bdd

在一个将serenity.version设置为2.0.30的Maven项目中,我具有以下测试依赖项

    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-junit</artifactId>
        <version>${serenity.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-screenplay</artifactId>
        <version>${serenity.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-screenplay-webdriver</artifactId>
        <version>${serenity.version}</version>
        <scope>test</scope>
    </dependency>

您可以看到here所有serenity-core-2.0.30的硒依赖性都设置为3.141.59

运行mvn -U dependency:tree -Dincludes=org.seleniumhq.selenium输出以下内容

[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ core ---
[INFO] <snip>
[INFO] \- net.serenity-bdd:serenity-junit:jar:2.0.30:test
[INFO]    \- net.serenity-bdd:serenity-core:jar:2.0.30:test
[INFO]       +- org.seleniumhq.selenium:selenium-server:jar:3.141.59:test
[INFO]       |  +- org.seleniumhq.selenium:selenium-firefox-driver:jar:3.9.1:test
[INFO]       |  +- org.seleniumhq.selenium:selenium-ie-driver:jar:3.9.1:test
[INFO]       |  \- org.seleniumhq.selenium:jetty-repacked:jar:9.4.12.v20180830:test
[INFO]       +- org.seleniumhq.selenium:selenium-java:jar:3.9.1:test
[INFO]       +- org.seleniumhq.selenium:selenium-api:jar:3.9.1:test
[INFO]       +- org.seleniumhq.selenium:selenium-chrome-driver:jar:3.9.1:test
[INFO]       +- org.seleniumhq.selenium:selenium-edge-driver:jar:3.9.1:test
[INFO]       +- org.seleniumhq.selenium:selenium-remote-driver:jar:3.9.1:test
[INFO]       +- org.seleniumhq.selenium:selenium-safari-driver:jar:3.9.1:test
[INFO]       +- org.seleniumhq.selenium:selenium-opera-driver:jar:3.9.1:test
[INFO]       +- org.seleniumhq.selenium:selenium-support:jar:3.9.1:test
[INFO]       \- org.seleniumhq.selenium:htmlunit-driver:jar:2.29.3:test

我必须添加以下依赖项以避免运行时错误-为什么使用版本3.9.1以及如何避免这种情况?

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-api</artifactId>
        <version>3.141.59</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-support</artifactId>
        <version>3.141.59</version>
        <scope>test</scope>
    </dependency>

1 个答案:

答案 0 :(得分:0)

事实证明,spring-boot-dependencies-2.0.3.RELEASE将属性selenium.version设置为3.9.1,并在其dependencyManagement部分中列出了除硒服务器工件以外的所有对象-在我的设置selenium.version POM解决了该问题。