Java NoSuchMethodError:Lorg/junit/platform/commons/function/Try;

Java NoSuchMethodError:Lorg/junit/platform/commons/function/Try;,java,unit-testing,junit,junit-jupiter,Java,Unit Testing,Junit,Junit Jupiter,我想使用最新的JUnit版本: <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.4.0</version> <scope>te

我想使用最新的JUnit版本:

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.25.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.1.3.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>

你知道我怎样才能解决这个问题吗?我使用Java 11。

此错误是由Spring的依赖项管理启动器poms和您的pom.xml配置引起的。 SpringBootStarter测试正在获取JUnit4,您需要排除它

如果使用以下pom.xml配置,您应该能够修复它:

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.25.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>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>

org.mockito
莫基托磁芯
2.25.0
测试
org.springframework.boot
弹簧起动试验
测试
朱尼特
朱尼特
org.junit.jupiter
朱尼特朱庇特
5.4.0
测试

您正在使用的实现Jupiter软件包的代码?可能重复的代码可能需要junit platform commons,因为这是junit Jupiter api和Apigardian api的依赖项,最后是opentest4j。对于junit Jupiter引擎,您需要junit platform引擎。这就是所有的依赖关系。
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>2.25.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>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>