JHipter生成网关项目集成测试构建失败原因问询
JHipter网关项目Maven构建测试失败原因分析
问题描述
在JHipter生成的网关项目中执行以下构建命令:
.\mvnw -ntp -Pprod verify jib:dockerBuild
出现测试执行失败错误,完整报错栈如下:
[ERROR] java.util.ServiceConfigurationError: org.junit.platform.launcher.TestExecutionListener: Provider reactor.blockhound.junit.platform.BlockHoundTestExecutionListener could not be instantiated [INFO] [INFO] Results: [INFO] [INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 50.194 s [INFO] Finished at: 2022-08-25T12:08:57+01:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M7:test (default-test) on project my-gateway: [ERROR] [ERROR] Please refer to D:\Work\S2M\monitoring_proj\myGateway\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] java.util.ServiceConfigurationError: org.junit.platform.launcher.TestExecutionListener: Provider reactor.blockhound.junit.platform.BlockHoundTestExecutionListener could not be instantiated [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process [ERROR] java.util.ServiceConfigurationError: org.junit.platform.launcher.TestExecutionListener: Provider reactor.blockhound.junit.platform.BlockHoundTestExecutionListener could not be instantiated [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:701) [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:311) [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:268) [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1334) [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1167) [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:931) [ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:370) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:351) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:215) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:171) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:163) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) [ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) [ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:294) [ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192) [ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105) [ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:960) [ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293) [ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:196) [ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566) [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282) [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225) [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406) [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347) [ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566) [ERROR] at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:53) [ERROR] at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:152) [ERROR] at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:76) [ERROR] [ERROR] -> [Help 1]
使用以下命令跳过测试后构建成功:
.\mvnw -ntp -Pprod verify jib:dockerBuild -DskipTests=true
失败原因分析
核心错误是ServiceConfigurationError,说明JVM无法实例化BlockHoundTestExecutionListener这个JUnit测试执行监听器,常见触发原因包括:
- 依赖版本不兼容:BlockHound与JUnit平台、Spring Boot或JHipter生成的其他依赖版本不匹配,导致监听器类无法适配当前JUnit的API规范。
- 依赖范围配置错误:BlockHound相关依赖仅在
dev或test环境引入,而prodprofile下未包含该依赖,导致类加载失败。 - Surefire插件问题:当前使用的Surefire插件版本为3.0.0-M7(预览版),存在fork进程时的类加载路径异常,无法正确加载监听器类。
- JDK版本冲突:BlockHound对JDK版本有要求,若使用的JDK版本不在支持范围内(如过于老旧或超前),会导致类实例化失败。
排查与修复建议
- 核对依赖版本:检查
pom.xml中reactor-blockhound-junit-platform的版本,确保与JHipter官方推荐版本、JUnit Platform及Spring Boot版本兼容。 - 调整依赖范围:确认BlockHound依赖在
prodprofile下也能被加载,避免仅将其配置在test或dev范围。 - 升级Surefire插件:将当前预览版的Surefire插件升级到稳定版本(如3.2.5及以上),解决fork进程的类加载问题。
- 检查JDK版本:确保项目使用的JDK版本符合BlockHound要求(通常为JDK 8及以上),避免版本不兼容。
- 查看详细日志:访问
target/surefire-reports目录下的日志文件,找到监听器无法实例化的具体触发原因(如ClassNotFoundException、NoSuchMethodError等),精准定位问题。
内容的提问来源于stack exchange,提问作者Khadija
相关产品推荐
相关产品推荐

