我有一个使用 Spring Boot 和 Junit 5 的简单应用程序:
使用 Spring Boot 2.1(例如 2.1.8 或 2.1.12)时,我的单元测试运行顺利
使用 Spring Boot 2.2(例如 2.2.2.RELEASE 或 2.3.2.RELEASE)时,我的单元测试失败并显示错误消息
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project XXX: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Projets\workspace\XXX\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] TestEngine with ID 'junit-vintage' failed to discover tests
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There …Run Code Online (Sandbox Code Playgroud) 在我的 POM 中,我将 Spring Boot 的版本从 2.3.5.RELEASE 升级到 2.4.2。结果,mvn clean test现在失败并出现错误
java.lang.NoClassDefFoundError: org/springframework/test/context/TestContextAnnotationUtils
Caused by: java.lang.ClassNotFoundException: org.springframework.test.context.TestContextAnnotationUtils
Run Code Online (Sandbox Code Playgroud)
在一个简单的测试中
package ch.ge.ael.enu.mediation;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MediationApplicationTests {
@Test
void contextLoads() {
}
}
Run Code Online (Sandbox Code Playgroud)
有人有线索吗?
我有一个JDK 9项目.运行时mvn install,一切正常.当IntelliJ 2017.2.6与JDK 9.0.4一起使用时,由于拆分包,我想出了许多编译错误.例如,在我的POM中我设置了一个依赖org.apache.solr:solr-core:7.2.1.IntelliJ显示的错误之一是:
Error:java: module solr.core reads package org.apache.lucene.search from both lucene.misc and lucene.sandbox
Run Code Online (Sandbox Code Playgroud)
IntelliJ发出的编译错误的基本原理是:
solr-coreMaven依赖于工件lucene-misc和lucene-sandboxlucene-misc.jar并lucene-sandbox.jar定义类在包org.apache.lucene.searchlucene-misc.jar并且lucene-sandbox.jar是JDK 9模块(事实上,它们不是模块,它们没有module-info.java文件).由于两个JDK 9模块无法参与同一个包,因此IntelliJ会发出编译错误.相比之下,Maven编译器插件没有出错,因为它认为lucene-misc.jar并且lucene-sandbox.jar属于类路径,而不是模块路径.
我显然不想重新包装Lucene的东西.
所以我的问题归结为以下几点:如何将IntelliJ错误静音Error:java: module Mod1 reads package P from both Mod2 and Mod3?