运行maven (3.5.2)构建的Spring Boot 2.0.2 generated应用程序(由具有web依赖关系的web初始化程序生成)无法执行maven-surefire-plugin,原因如下:
错误:无法找到或加载主类org.apache.maven.surefire.booter.ForkedBooter
原因: java.lang.ClassNotFoundException:org.apache.maven.surefire.booter.ForkedBooter
为什么会发生这种情况?是不是boot + surefire集成的问题= bug?
作为参考,看起来相关的依赖项是:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/>
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
发布于 2018-06-03 06:21:14
该问题的解决方法是覆盖Spring Boot的maven-surefire-plugin
定义,并将useSystemClassLoader
设置为false
。请阅读Surefire docs了解更多详细信息
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
发布于 2018-10-31 20:52:16
jediz提供的<useSystemClassLoader>false</useSystemClassLoader>
解决方案确实允许我的surefire测试运行,但在我的一些Spring Boot集成测试中破坏了类加载。
下面的maven-surefire-plugin配置对我有效:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
</configuration>
</plugin>
发布于 2018-11-12 19:42:43
这是由于known bug in the Maven Surefire plugin造成的。在3.0.0-M1版本中已修复,该版本为released in November 2018。因此,最简单、最可靠的修复方法是升级您使用的插件的版本。
将maven-surefire-plugin从2.12.4更新到3.0.0-M1对我有效。该项目没有显式地使用插件,所以我必须添加一个新的插件依赖项。
<plugins>
...
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
...
</plugins>
https://stackoverflow.com/questions/50661648
复制相似问题