Maven 依赖关系显示在依赖树中,但没有导入 jar

Maven dependency shows in dependency tree but no jar is imported

我工作的项目有很多层次和一个父pom,所以很难评估导入依赖项的最终结果。

但是,查看 dependency:tree 和有效的 pom,我可以看到我正在正确导入 JUnit-jupiter 5.5.2,但是我在项目的 Maven 依赖项列表中看不到 jar,我实际上看到了 JUnit-jupiter 5.2.0 。

已经尝试过 mvc clean install -U

有什么想法吗?

罐子和 dependecy:tree

有效 pom

JUnit-jupiter 5.2.0 仍在您的项目中的原因可能是因为它作为其他依赖项的传递依赖项出现。您可以做的是查找 JUnit-jupiter 5.2.0 的父依赖项并从中排除传递依赖项。

使用项目的图形依赖树并展开所有传递依赖并搜索 jupiter 库。 如果有 JUnit-jupiter 5.2.0 作为传递依赖项,您可以按如下方式排除它。

    <dependency>
        <groupId>it.some.parent</groupId>
        <artifactId>parent-library</artifactId>
        <version>${parent.library.version}</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>*</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

通过在 pom 的依赖管理中排除传递依赖,设法导入正确的 jar:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>${spring-boot.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>