为什么即使在排除时 Maven 也不排除测试依赖?

问题描述

我有以下...

<dependency>
        <groupId>com.github.stefanbirkner</groupId>
        <artifactId>system-rules</artifactId>
        <version>[1.19.0,)</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
</dependency>
<dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13.2</version>
        <scope>test</scope>
</dependency>

但是当我运行 mvn clean package 时,我得到...

Dependency convergence error for junit:junit:4.11 paths to dependency are:
+-my.pkg:project:0.0.3-SNAPSHOT
  +-com.github.stefanbirkner:system-rules:1.19.0
    +-junit:junit:4.11
and
+-my.pkg:project:0.0.3-SNAPSHOT
  +-junit:junit:4.13.2

为什么不忽略 dep?

解决方法

“修复”依赖收敛错误的真正方法是使用 <dependencyManagement>

放入条目

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13.2</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
</dependencyManagement>

进入 POM。这将为所有传递依赖项设置版本。不再需要排除。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...