请帮我解决这个问题。我不太明白日志中的错误是什么意思。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.749s
[INFO] Finished at: Thu Apr 24 10:10:20 IST 2014
[INFO] Final Memory: 15M/37M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test (default-test) on project samples.simpleforwarding: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?
[ERROR] Command wascmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0_55\jre\bin\java" -Xmx1024m -XX:MaxPermSize=256m -jar E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefirebooter53410321571238933.jar E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefire86076271125218001tmp E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefire_01846991116135903536tmp"
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

当前回答

我最近在JHipster 6.10.5使用spring-boot 2.2.7生成的应用程序中遇到了同样的问题。RELEASE和maven surefire插件3.0.0-M4。这是由于非常长的测试日志造成的超时。通过在pom.xml中的maven-surefire-plugin(在pluginManagement下)中添加以下配置参数来解决:

1200年< forkedProcessExitTimeoutInSeconds > < / forkedProcessExitTimeoutInSeconds >

看到https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html forkedProcessExitTimeoutInSeconds

其他回答

我更新了surefire插件如下,这解决了我的问题:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                    <forkCount>1</forkCount>
                    <reuseForks>true</reuseForks>
                    <runOrder>alphabetical</runOrder>
                </configuration>
            </plugin>

关闭maven-surefile-plugin的useSystemClassLoader应该会有帮助

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.0</version>
    <configuration>
        <useSystemClassLoader>false</useSystemClassLoader>
    </configuration>
</plugin>

我有这么多时间,对我来说,这几乎总是与“控制台”有关,与实际的分叉无关。

总之,我的解决方案是:

添加-B(批处理模式) 添加JVM参数-Djansi。力= true -Djansi.passthrough = true

在一个给定的项目中,这将在一个新的windows控制台系统失败(cmd.exe)

[path_to_jdk] \ java.exe -Dmaven.home=[path_to_maven]\apache-maven-3.6.3 -Dclassworlds.conf=[path_to_maven]\bin. \bin\m2.conf -Dmaven.home=[path_to_maven]multiModuleProjectDirectory = path_to_myproject -Dfile。utf - 8编码= -Djansi。力= true -Djansi。passthrough=true -classpath [path_to_maven]\boot\plexus-classworlds-2.6.0.jar org.codehaus.plexus.classworlds.launcher.Launcher清洁安装

这将始终在一个新的控制台窗口(cmd.exe)中工作。

[path_to_jdk] \ java.exe -Dmaven.home=[path_to_maven]\apache-maven-3.6.3 -Dclassworlds.conf=[path_to_maven]\bin. \bin\m2.conf -Dmaven.home=[path_to_maven]multiModuleProjectDirectory = path_to_myproject -Dfile。utf - 8编码= -Djansi。力= true -Djansi。passthrough=true -classpath [path_to_maven]\boot\plexus-classworlds-2.6.0.jar org.codehaus.plexus.classworlds.launcher.Launcher清洁安装

注意,这两个命令都有-B(批处理模式,应该关闭着色),唯一的区别是

-Djansi.force=true -Djansi.passthrough=true

现在我只需要能够将这些“JVM参数”传递给“mvn”。Cmd”以使其更好。

我猜是这样的:有没有一种方法通过命令行将jvm参数传递给maven?


一点背景知识:

从maven (3. exe)的最新版本开始,我就反复遇到这个问题。x +)。 我尝试过这里的许多解决方案,有时运气好,有时不好。

这篇来自官方文档的文章一直都没用:https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html

但有一些常数,当我处理这个问题时

总是在窗口,本地 总是有大量的控制台输出。 并不是所有的团队开发人员都会在特定项目中犯错误 Jenkins的构建会通过 IT测试中的大量控制台输出(故障安全集成测试)

关键的发现是,我注意到在Eclipse中(有或没有嵌入式maven版本),完整的maven构建(干净安装)都可以工作。

因此,我弄清楚了Eclipse使用的是哪个命令(谢谢:我如何获得Eclipse运行配置的命令行?)

从那里,我可以确定解是什么。

看看人们说的其他答案

输出到日志文件 降低日志级别 https://stackoverflow.com/a/52033799/1634131 https://stackoverflow.com/a/64132709/1634131 等

这里显然有一个bug。或者在Maven中,或者在windows控制台中,或者在Jansi库中,或者在这些组件的集成中。

我的设想是

我的测试有很多日志输出(我的意思是很多!) Surefire插件v2.22.2 错误只发生在IDE内部,如果从命令行执行mvn命令则不会发生。 没有迹象显示Surefire插件中的任何.dump文件或Java二进制中的传统hs_err崩溃文件。

对我来说,有两件事一直是解决方案(它们是替代方案):

不使用fork:设置Surefire插件属性forkcount = 0。 增加Surefire插件属性 forkedProcessExitTimeoutInSeconds从30秒变成300秒。插件文档说,如果这个超时被击中,你会看到错误消息有一个超时在fork。我没有看到这样的错误消息,但是它一直在修复这个问题以增加这个超时值。

您可能希望使用解决方案(2),因为分叉是可取的。

Why?

我的理论是,如果有大量的日志输出,那么在fork关闭时仍然需要进行大量的处理(特别是如果您在一个IDE中运行,该IDE捕获输出并可能为其窗口内容使用内存映射文件)。简而言之:在测试完成时,仍有大量文本等待转发到IDE中。30岁似乎还不够。

这也解释了为什么有些开发者能够发现问题,而有些开发者却不能。在测试结束时,剩下多少输出处理可能是cpu功率、磁盘速度等的函数。

如果我在这一点上是正确的-不能证明它-那么所有的建议,如重定向日志输出和降低日志级别都是IMO处理症状,而不是原因。

最近travis终止了一个测试的执行(没有改变任何相关的东西(以及在开发人员机器上成功的构建!)),因此BUILD FAILURE。 原因之一是这样的(见@agudian的答案):

Surefire不支持调用System.exit()的测试或任何引用库

(因为测试类确实称为System.exit(-1))。

相反,使用简单的return语句会有所帮助。 为了让travis再次开心,我还必须添加@xiaohuo提供的surefire参数(<argLine>)。(此外,我必须删除-XX:MaxPermSize=256m,以便能够在我的一个台式机上构建)

只做这两件事中的一件是行不通的。

要了解更多背景知识,请阅读何时调用系统。退出Java。