【问题标题】:why auto dependency is error version?(java.lang.ClassNotFoundException: org.junit.jupiter.api.MethodOrdererContext)为什么自动依赖是错误版本?(java.lang.ClassNotFoundException:org.junit.jupiter.api.MethodOrdererContext)
【发布时间】:2019-07-12 19:41:27
【问题描述】:

我想知道为什么与 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

【问题讨论】:

  • 您使用的是 Spring Boot 还是管理依赖版本的工具?
  • @Sam Brannen:谢谢。我使用org.springframework.boot:spring-boot-starter-test:2.1.2.RELEASE。我在spring-boot-test-2.1.2.RELEASE.pom 中找到org.junit.jupiter 的依赖:``` org.junit.jupiterjunit-jupiter-api5.3.2 version> compiletrue ``` 所以,这就是原因。

标签: java maven junit5


【解决方案1】:

在将 Spring Boot 依赖项更新到最新版本并将 Juiper 引擎版本更新到 5.6.1 后,我遇到了类似的问题。

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

【讨论】:

    【解决方案2】:

    这是Gradle 5 JUnit BOM and Spring Boot Incorrect Versions 的副本。

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

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

    【讨论】:

    • 这仍然适用于 5.8.0-M1 版本
    • 谢谢,工作正常!
    猜你喜欢
    • 2021-03-03
    • 1970-01-01
    • 2017-05-07
    • 2019-07-23
    • 2017-12-26
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 2017-01-01
    相关资源
    最近更新 更多