java - 为什么自动依赖是错误版本?(java.lang.ClassNotFoundException : org. junit.jupiter.api.MethodOrdererContext)

标签 java maven junit5

我想知道为什么与 junit-jupiter-engine-5.4.0.pom 定义的不一样。

当我显式声明 junit-jupiter-api 和 junit-platform-engine 版本与 junit-jupiter-engine-5.4.0.pom 相同时,问题就解决了。

pom:

<dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.4.0</version>
      <scope>test</scope>
</dependency>

问题:

junit-jupiter-engine-5.4.0.pom 依赖项是

<dependency>
      <groupId>org.apiguardian</groupId>
      <artifactId>apiguardian-api</artifactId>
      <version>1.0.0</version>
      <scope>compile</scope>
</dependency>
<dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-engine</artifactId>
      <version>1.4.0</version>
      <scope>compile</scope>
</dependency>
<dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.4.0</version>
      <scope>compile</scope>
</dependency>

但我运行 mvn dependency:tree ,结果是这样的:

[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.4.0:test
[INFO] |  +- org.apiguardian:apiguardian-api:jar:1.0.0:test
[INFO] |  +- org.junit.platform:junit-platform-engine:jar:1.3.2:test
[INFO] |  |  +- org.junit.platform:junit-platform-commons:jar:1.3.2:test
[INFO] |  |  \- org.opentest4j:opentest4j:jar:1.1.1:test
[INFO] |  \- org.junit.jupiter:junit-jupiter-api:jar:5.3.2:test
构建工具:maven3.5.4

最佳答案

这是 Gradle 5 JUnit BOM and Spring Boot Incorrect Versions 的重复项.

解决方案是将以下内容添加到您的 Maven POM。

<properties>
    <junit-jupiter.version>5.4.0</junit-jupiter.version>
</properties>

关于java - 为什么自动依赖是错误版本?(java.lang.ClassNotFoundException : org. junit.jupiter.api.MethodOrdererContext),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54763937/

相关文章:

java - Java 中的 File.exists 有多贵

java - maven settings.xml 中的存储库与pluginRepositories

scala - 如何在scala中使用相对路径读取文本文件

java - Maven使用本地依赖并得到NoClassDefFoundError : javax/transaction/Synchronization

java - 您可以使用 JNI 在从 Java 调用的 C++ 函数中创建新的 JVM 吗?

java - Swing 是否支持 Windows 7 样式的文件选择器?

java - 如何使用@csvsource更改junit参数化测试的csvparsersettings

intellij-idea - 无法解析 junit 平台启动器 1.6.3 intellij

Java:如果抽象类Foo返回Object,具体类Bar可以返回String或Integer吗?

java - 是否可以参数化 @BeforeEach,即根据每个 @Test 给出的参数调用不同的 @BeforeEach?