如何从(传递)依赖项中排除某些程序包?

时间:2020-04-13 03:03:43

标签: maven dependency-tree

我依靠org.springframework.boot:spring-boot-starter-validation:jar:2.2.6.RELEASE:test,而依靠org.hibernate.validator:hibernate-validator:jar:6.0.18.Final:test

[INFO] +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.6.RELEASE:test
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.33:test
[INFO] |  \- org.hibernate.validator:hibernate-validator:jar:6.0.18.Final:test

现在在我的测试案例中,有两个候选静态导入assertNotNull

一个是

import static org.junit.jupiter.api.Assertions.assertNotNull;

另一个是

import static org.hibernate.validator.internal.util.Contracts.assertNotNull;

有什么好方法可以排除休眠模式吗?

2 个答案:

答案 0 :(得分:2)

您只能排除整个依赖性,而不能排除其中的一部分。

答案 1 :(得分:0)

您可以尝试这样做:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
    <version>2.2.6.RELEASE</version>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
        </exclusion>
    </exclusions>
</dependency>