Junit5 与 Hive 的依赖冲突

Junit5 与 Hive 的依赖冲突


今天在给一个旧工程添加 hive 依赖后,出现测试方法报错的问题,而且之前能正常跑的测试方法,现在也一样报错

1.png
1


仔细看上面报错信息,里面报的 junit 版本是 3.8.1 版,而这个项目使用的依赖是 5.7.2 版,推测是依赖冲突引起的问题

1
2
3
4
5
6
7
        <!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.7.2</version>
            <scope>provided</scope>
        </dependency>

检查依赖树,证实是 hive –» zookeeper –» jline 引入了 3.8.1 的 junit

2.png
2


改用 4.13.2 的 junit

1
2
3
4
5
6
7
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>provided</scope>
        </dependency>
3.png
3

此时,被依赖树引入的 3.8.1 版的 junit 会因为与 4.13.2 版的存在冲突而被自动省略

而使用 5.7.2 版的的时候,3.8.1 版的 junit 之所以不会被自动省略,是因为 v5 开始使用新的 <groupId><artifactId> 的原因:

4.png
4

使用 5.7.2 版的的时候,可以给 hive 依赖添加 junit 依赖的排除

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
        <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-exec</artifactId>
            <version>2.3.9</version>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
5.png
5

相关内容