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

Why does maven ignore versions of compile transitive dependencies defined in test dependency

我在 Maven 项目中有以下测试依赖项,其中 serenity.version 设置为 2.0.30

    <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 的所有 selenium 依赖项都设置为 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>

事实证明 spring-boot-dependencies-2.0.3.RELEASE 将 属性 selenium.version 设置为 3.9.1 并列出除 selenium-server 之外的所有内容它的 dependencyManagement 部分中的工件 - 在我的 POM 中设置 selenium.version 解决了这个问题。