问题描述
我想在Spring Boot应用程序上运行JUnit 5.4+测试,以便可以在测试中使用@Order批注.但是,无论尝试什么,Maven都会将我的POM解析为5.3.2.我尝试过包括所有我可以手动想到的依赖项,但是最终我得到了许多不匹配的版本.我还尝试清除整个〜/.m2/repository文件夹并重建树,结果相同.
I want to run JUnit 5.4+ tests on my Spring Boot app so that I can use the @Order annotation on my tests. However, Maven resolves my POM to 5.3.2 regardless of what I try.I've tried including all the dependencies I can think of manually, but then I end up with a mess of mismatched versions. I also tried clearing my entire ~/.m2/repository folder and rebuilding the tree, same results.
mvn依赖项的相关部分:树
Relevant parts of mvn dependency:tree
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.5.0:test
[INFO] | +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | \- org.junit.platform:junit-platform-commons:jar:1.3.2:test
[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.5.0:test
[INFO] | +- org.junit.jupiter:junit-jupiter-params:jar:5.3.2:test
[INFO] | \- org.junit.jupiter:junit-jupiter-engine:jar:5.3.2:test
[INFO] | \- org.junit.platform:junit-platform-engine:jar:1.3.2:test
pom.xml的一部分
Part of the pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
...
5.3.2来自哪里?
Where does the 5.3.2 come from?
推荐答案
将此行添加到Maven pom.xml
中的属性中:
Add this line to your the properties in your Maven pom.xml
:
<junit-jupiter.version>5.5.0</junit-jupiter.version>
这将控制spring boot poms(org.springframework.boot:spring-boot-dependencies
)中的依赖项管理中定义的依赖项.
this will control the dependencies defined in dependency management within the spring boot poms (org.springframework.boot:spring-boot-dependencies
).
原因是:org.springframework.boot:spring-boot-dependencies
包含junit-bom
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit-jupiter.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
默认情况下,junit-jupiter.version
是5.3.2
.因此,只要您不更改junit-jupiter.version
,此Bom就会定义所有未明确列出的依赖项(例如org.junit.jupiter:junit-jupiter-params
)都是org.junit:junit-bom:5.3.2
per default junit-jupiter.version
is 5.3.2
. So as long as you not change junit-jupiter.version
, this bom will define that all not explicit listed dependencies (for example org.junit.jupiter:junit-jupiter-params
) are of the version defined in org.junit:junit-bom:5.3.2
这篇关于依赖项中的JUnit版本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!