Maven Failsafe 插件 - SurefireBooterForkException: 分叉进程中出现错误 (TypeNotPresentExceptionProxy)
Posted
技术标签:
【中文标题】Maven Failsafe 插件 - SurefireBooterForkException: 分叉进程中出现错误 (TypeNotPresentExceptionProxy)【英文标题】:Maven Failsafe plugin - SurefireBooterForkException: There was an error in the forked process (TypeNotPresentExceptionProxy) 【发布时间】:2018-08-28 00:40:40 【问题描述】:我在运行 mvn clean verify -P P1
时得到这个奇怪的堆栈跟踪
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.21.0:verify (default) on project prj-name: There are test failures.
[ERROR]
[ERROR] Please refer to C:\path\to\project\target\failsafe-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] sun.reflect.annotation.TypeNotPresentExceptionProxy
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:658)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:533)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:278)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:244)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1149)
什么意思?
Maven pom.xml:
<profiles>
<profile>
<id>P1</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<encoding>UTF-8</encoding>
<!-- Includes integration tests -->
<includes>
<include>**/integration/*.java</include>
<include>**/integration/*/*.java</include>
</includes>
<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
更新
有一个万无一失的转储流文件
ForkStarter IOException: For input string: "1;5".
org.apache.maven.plugin.surefire.booterclient.output.MultipleFailureException: For input string: "1;5"
at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.<init>(ThreadedStreamConsumer.java:58)
at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer.<init>(ThreadedStreamConsumer.java:110)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:596)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:533)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:278)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:244)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1149)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:978)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:854)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:200)
at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:196)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
由于字符串变量中的垃圾以及日志中偶尔出现的IndexOutOfBoundsException
/ ConcurrentModificationException
,这似乎是一个并发问题。
【问题讨论】:
【参考方案1】:这个 GitHub 问题 - [#6254] Maven-failsafe-plugin fails to execute integration tests - 以及相关讨论帮助我解决了我的问题。
这是一个错误。事实证明,较新的 Failsafe 插件版本(2.19.0 及更高版本)不适用于 Spring Boot 1.4(或更高版本)。解决方法是将 maven-failsafe-plugin 降级到 2.18.1。这是更新后的 pom.xml:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<!-- I don't specify version at all (Spring Boot can autoconfigure plugin version) -->
<executions>
<execution>
<!-- changed <id> to <phase>, but I don't know whether it's important or not. -->
<phase>integration-test</phase>
<!-- ... no changes here: the same as in the question ... -->
</execution>
</executions>
</plugin>
</plugins>
【讨论】:
基本上,较新的版本针对 JAR 进行测试,而在 v2.18.1 之前,故障安全使用 test-class。 这个配置根本不运行集成测试。这不是一个正确的答案。 @burtsevyg,你如何运行集成测试?试试mvn verify
命令。
我运行mvn deploy
。
@burtsevyg mvn deploy
也应该可以工作。尝试mvn verify
进行比较,看看它是否运行您的集成测试。你遵循命名约定吗?默认情况下,Failsafe 插件运行名为 */IT.java
、**/*IT.java
和 **/*ITCase.java
的测试类。【参考方案2】:
我遵循了这里提出的解决方案: https://github.com/spring-projects/spring-boot/issues/6254#issuecomment-307151464
目前,我有故障安全插件 2.22.0,我可以通过显式配置 classesDirectory
属性来使用此版本而不是降级:
<classesDirectory>$project.build.outputDirectory</classesDirectory>
例子:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
<configuration>
...
<classesDirectory>$project.build.outputDirectory</classesDirectory>
...
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
解决方法的另一种变体稍后在同一个 Github 问题线程中描述:https://github.com/spring-projects/spring-boot/issues/6254#issuecomment-343470070
<classesDirectory>$project.build.directory/$artifactId.jar.original</classesDirectory>
注意 (2020-02-27):maven-failsafe-plugin
版本 3.0.0-M4 仍然需要这些解决方法 :-(
【讨论】:
【参考方案3】:我的 testng 类有 LoginPageTest.java,我删除了 .java 并且工作得非常好。 :)
<classes>
<class name="com.qa.Backend.tests.LoginPageTest"/>
</classes>
【讨论】:
以上是关于Maven Failsafe 插件 - SurefireBooterForkException: 分叉进程中出现错误 (TypeNotPresentExceptionProxy)的主要内容,如果未能解决你的问题,请参考以下文章
Maven Failsafe 插件 - SurefireBooterForkException: 分叉进程中出现错误 (TypeNotPresentExceptionProxy)
Maven 构建和 maven-failsafe-plugin - 分叉的虚拟机在没有正确说再见的情况下终止