279

请帮我解决这个问题。我不完全理解日志中的错误是什么意思。

[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
4

61 回答 61

185

我有同样的问题并通过添加解决:

<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>

整个插件元素是:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <forkCount>3</forkCount>
    <reuseForks>true</reuseForks>
    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
  </configuration>
</plugin>
于 2015-11-17T13:12:58.820 回答
153

在我的情况下,问题与输出到 IntelliJ IDEA 控制台(OS windows 10)的日志太长有关。

命令:

mvn clean install

这个命令解决了我的问题:

mvn clean install > log-file.log
于 2018-08-27T06:41:42.817 回答
50

我有非常相似的问题(Maven build 和 maven-failsafe-plugin - 分叉的 VM 在没有正确说再见的情况下终止)并找到了三个对我有用的解决方案:

问题描述

问题在于 maven 插件maven-surefire-plugin仅在 2.20.1 和 2.21.0 版本中。我查了一下,你使用的是 2.20.1 版本。

解决方案 1

将插件版本升级到2.22.0。添加pom.xml

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

解决方案 2

将插件版本降级到2.20。添加pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.20</version>
</plugin>

解决方案 3

使用插件配置testFailureIgnore。添加pom.xml

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <testFailureIgnore>true</testFailureIgnore>
  </configuration>
</plugin>
于 2018-06-29T10:33:27.393 回答
36

Surefire 常见问题解答的这一部分可以帮助您:

Surefire 失败并显示消息“分叉的 VM 在没有正确说再见的情况下终止”

Surefire 不支持任何时候调用 System.exit() 的测试或任何引用的库。如果他们这样做,它们与 surefire 不兼容,您可能应该向库/供应商提出问题。或者,分叉的 VM 也可能由于多种原因而崩溃,这也可能导致此问题发生。查找指示 VM 崩溃的经典“hs_err*”文件,或在测试执行时检查运行 maven 的日志输出。崩溃进程的一些“异常”输出可能会转储到控制台/日志。如果这种情况发生在 CI 环境中并且仅在运行一段时间后,您的测试套件很有可能会泄漏某种操作系统级别的资源,从而使每次运行的情况变得更糟。常规的操作系统级别监控工具可能会给您一些指示。

于 2014-06-02T19:04:35.793 回答
35

截至今天(2018 年 10 月 30 日),我们注意到我们的构建在 Jenkins 中出现此错误。

该错误有点误导,需要查看转储的输出target/surefire-reports/ 以查看以下错误消息:

Error: Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter

这导致我看到以下 SO 帖子,其中提到了 OpenJDK 181 中可能存在的错误:Maven surefire could not find ForkedBooter class

该帖子中的任何一个修复程序都解决了我的问题。具体来说,我使用了其中之一:

  1. 从 docker 容器中的构建切换maven:3.5.4-jdk-8maven:3.5.4-jdk-8-alpine
  2. 覆盖 Spring Boot 的类加载器在此处详述:https ://stackoverflow.com/a/50661649/1228408
于 2018-10-30T18:24:29.900 回答
13

关闭 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>
于 2018-11-22T13:53:37.853 回答
10

刚刚面临同样的问题,ubuntu上的java 8

然后遇到了https://stackoverflow.com/a/53016532/1676516

使用 java 8 https://issues.apache.org/jira/browse/SUREFIRE-1588的 surefire 插件版本 2.22.1 中似乎最近出现了一个错误

通过本地 mvn 设置遵循建议的解决方法~/.m2/settings.xml

<profiles>
    <profile>
        <id>SUREFIRE-1588</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
        </properties>
    </profile>
</profiles>
于 2018-11-05T07:06:15.093 回答
9

我今天遇到了同样的问题,对我来说,真正的问题在日志中进一步报告了 message Cannot use a threadCount parameter less than 1; 1 > 0。在添加<threadCount>1</threadCount>surefire-plugin 配置时,其他错误消失了。

完整的插件配置:
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.18.1</version>
                </dependency>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-testng</artifactId>
                    <version>2.18.1</version>
                </dependency>
            </dependencies>
            <configuration>
                <threadCount>1</threadCount>
            </configuration>
        </plugin>

...是的,出于向后兼容性的原因,我在这个测试框架中同时使用了 junit 和 testng。

于 2015-07-30T09:22:15.297 回答
9

升级到 java 12 后我遇到了类似的问题,对我来说解决方案是更新 jacoco 版本<jacoco.version>0.8.3</jacoco.version>

于 2019-11-06T15:18:20.127 回答
9

2.22.2 版在分叉 JVM 方面存在实际问题。使用版本 2.20 - 它就像一个魅力!


<groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
于 2020-01-06T16:04:35.013 回答
8

使用 maven surefire 2.21.0 我解决了将reuseForks选项值从true更改为false的问题:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <reuseForks>false</reuseForks>
            </configuration>
        </plugin>
    </plugins>
</build>

我在构建下的整个配置部分看起来像:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <configuration>
                <testFailureIgnore>true</testFailureIgnore>
                <skip>false</skip>
                <reuseForks>false</reuseForks>
                <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                <argLine>-Dfile.encoding=UTF-8</argLine>
                <useSystemClassLoader>false</useSystemClassLoader>
                <includes>
                    <!--Test* classes for the app testing -->
                    <include>**/directory/Test*.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>
于 2019-02-20T10:36:02.827 回答
8

我遇到过一个案例,提供的答案都没有解决问题。它与一个恰好使用 log4j 和 SLF4J/logback 的遗留应用程序有关。

之前的情况:clean test从 Eclipse 中启动构建运行良好,但在命令行启动时,出现此错误。基于 CircleCI 的 CI 也运行良好。

我所做的:出于纯粹的猜测,是配置适当的logback-test.xml并降低日志记录的详细程度。瞧,我不再遇到此错误,我现在可以从命令行构建项目(以及发生此错误的模块)。

我的观点是,使用或配置日志框架的方式可能是另一种解释

log4j 和 logback 之间真的有冲突吗?或者仅仅是测试产生的大量日志以某种方式溢出了命令行缓冲区?我不知道。这对我来说仍然是一个谜。

于 2018-08-06T12:48:14.347 回答
7

我的情况是

  • 我的测试有很多日志输出(我的意思是很多!)
  • Surefire 插件 v2.22.2
  • 该错误仅发生在 IDE 内部,而不是mvn从命令行执行命令时发生。
  • .dump没有任何来自 Surefire 插件的文件或hs_err来自 Java 二进制文件的传统崩溃文件的迹象。

有两件事一直是我的解决方案(它们是替代品):

  1. 不要使用分叉:设置 Surefire 插件属性forkcount = 0
  2. 将 Surefire 插件属性 forkedProcessExitTimeoutInSeconds从 30 秒增加到 300 秒。插件文档说,如果遇到此超时,您将看到错误消息There was a timeout in the fork。我没有看到这样的错误消息,但它始终如一地解决了增加此超时值的问题。

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

为什么?

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

这也解释了为什么有些开发者会看到问题,而有些则看不到。在测试完成时还剩下多少输出处理可能是 CPU 功率、磁盘速度等的函数。

如果我在这方面是对的——无法证明——那么所有的建议,比如重定向日志输出和降低日志级别,都是 IMO 治疗症状,而不是原因。

于 2021-04-15T16:37:40.863 回答
7

我在 Jenkins Docker 容器中也遇到了这个问题(试过 jenkins:lts、jenkins、jenkins:slim 和 jenkins:slim-lts。我不想遍历所有存储库并更新每个项目的 pom,所以我刚刚将 disableClassPathURLCheck 添加到 maven 命令行调用中:

mvn test -DargLine="-Djdk.net.URLClassPath.disableClassPathURLCheck=true"
于 2018-12-07T14:04:18.213 回答
7

如果有人包含自定义 argLine 参数,则必须重新考虑,因为它可能是内存分配问题的根源。

例如(我曾经有):

<argLine>XX:MaxPermSize=4096m ${argLine}</argLine>

现在我使用硬指定值:

<argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>

无论出于何种原因,与 Surefire 集成的应用程序(例如 Jacoco)都不需要足够的内存来与构建时发生的测试共存。

于 2016-08-12T19:59:23.860 回答
6

在 JDK 1.8.0_ 65上使用 Jacoco 插件运行 mvn 命令时遇到类似问题

[INFO]
A fatal error has been detected by the Java Runtime Environment:

JRE version: Java(TM) SE Runtime Environment (8.0_65-b17) (build 1.8.0_65-b17).........
Problematic frame:
PhaseIdealLoop::build_loop_late_post(Node*)+0x144
............
............
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test (default-test) on project 

 The forked VM terminated without properly saying goodbye. VM crash or System.exit called?

JDK https://bugs.openjdk.java.net/browse/JDK-8081379中有一个错误

解决方案是使用参数-XX:-UseLoopPredicate运行 mvn clean install

或者只是对 JDK 进行更新(我认为更新的次要版本有效)

于 2017-01-26T10:43:51.413 回答
5

这似乎是某些 Windows 机器上的线程同步问题。如果您在使用 Windows 时遇到此问题,请尝试将输出重定向到文件:mvn clean install > output.txt

于 2020-08-01T13:32:18.893 回答
4

您需要检查您的机器是 64 位还是 32 位。如果您的机器是 32 位,那么您的内存参数不应超过 4096,即使它应该低于 4 GB。但如果您的机器是 64 位,则安装 Java 64 位并在 mvn.bat 中提供指向 Java 64 位安装的 JAVA_HOME。

于 2015-02-16T07:32:08.920 回答
4

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

<forkedProcessExitTimeoutInSeconds>1200</forkedProcessExitTimeoutInSeconds>

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

于 2021-03-28T13:38:47.363 回答
4

我最近在使用 Bamboo 构建容器化 jar 应用程序时遇到了这个错误:

org.apache.maven.surefire.booter.SurefireBooterForkException:分叉的虚拟机在没有正确告别的情况下终止

经过几个小时的研究,我修复了它。我认为在这里分享我的解决方案会很有用。

因此,每次mvn clean package在 docker 容器中为 java 应用程序运行命令时都会发生错误。我不是 Maven 专家,但问题在于 spring-boot 中包含的 Surefire 和 Junit4 插件作为 Maven 依赖项。

要修复它,您需要将 Junit4 替换为 Junit5 并覆盖您的 Surefire 插件pom.xml

1.spring boot里面的依赖插入排除:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <!-- FIX BAMBOO DEPLOY>
    <exclusions>
        <exclusion>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </exclusion>
    </exclusions>
    <!---->
</dependency>

2.添加新的Junit5依赖:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>5.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-launcher</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-runner</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.junit.platform</groupId>
    <artifactId>junit-platform-surefire-provider</artifactId>
    <version>1.1.0</version>
    <scope>test</scope>
</dependency>

3.在插件部分插入新插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.1.0</version>
        </dependency>
    </dependencies>
</plugin>

这应该足以修复竹制建筑。不要忘记还转换所有 Junit4 测试以支持 Junit5。

于 2018-06-27T14:40:11.177 回答
4

我在使用 Java 8 和 spring boot 5.2.7 时遇到了同样的问题(包括插件,开箱即用)。插件的版本是默认的(2.22.2)。就我而言,问题仅发生在团队中的某些机器上,而在其他机器上一切都很好。我想这与检测到的核心数量有关。

我用这些设置修复了它:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <reuseForks>false</reuseForks>
            </configuration>
        </plugin>

我已经尝试了许多建议的方法,但在我的情况下没有任何效果。

此解决方案的唯一缺点是禁用分叉的重用,并且测试现在运行速度较慢。

于 2020-10-30T17:50:18.567 回答
3

测试中使用的分叉 JVM 内存不足。解决方案是禁用分叉 JVM 并在主 JVM 上运行测试以确保您有足够的内存或传递参数以增加分叉 JVM 的内存

查看此答案中的解决方案

于 2019-03-12T09:41:01.763 回答
3

您可以使用以下命令。因为您的单元测试需要分叉。关于您在单元测试中使用线程的问题。

mvn test -DforkCount=2

我希望。它很有帮助。

于 2021-07-16T10:30:22.317 回答
2

我将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>
于 2020-06-29T05:34:44.130 回答
2

在 pom.xml 中设置它对我有用。但是您应该查看文档以了解其他解决方法 https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html

       <plugin>

            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <!--these strange settings fixes a chrash and dumpstream from surefire when run from command line
                    Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.booter.ForkedBooter
                -->
                <useSystemClassLoader>true</useSystemClassLoader>
                <useManifestOnlyJar>false</useManifestOnlyJar>
            </configuration>
        </plugin>
于 2018-11-11T08:30:58.160 回答
2

我遇到了同样的问题,并通过使用 Oracle 的 Java 8 而不是 Openjdk 的 Java 10 解决了

于 2018-11-23T10:05:07.167 回答
2

您可以设置java选项

SET JAVA_OPTS='-Xmx1024m' XX:+UseLoopPredicate

mvn clean install

于 2018-10-31T07:36:55.697 回答
2

我对这个问题的解决方案是关闭该死的 chrome 浏览器,它阻塞了我的计算机内存

于 2018-10-03T14:38:52.680 回答
2

我在 MacOS 上也遇到了这个问题,同时在端口 5005 上远程调试 Selenium 测试代码。这个问题原来是由仍在运行的剩余的surefire-forked-JVM 引起的。Eclipse IDE 终端的日志输出没有显示Address already in use的根本问题。只有当我在 Eclipse 实际尝试运行的 MacOS 终端中运行相同的命令时,才会显示日志消息:

/bin/sh -c cd /path/to/your/project/directory && /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/bin/java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 -jar /path/to/target/surefire/surefirebooter230340673926465933.jar /path/to/target/surefire 2019-06-28T10-50-02_140-jvmRun1 surefire6455775580414993159tmp surefire_02461993428448591420tmp

杀死流氓 JVM 实例(在 Activity Monitor 中查找 java 进程名称)解决了这个问题。顺便说一句,我正在运行surefire插件版本2.21.0,打开jdk 8(v1.8.0_212)没有问题。请注意,所有路径都特定于您的构建环境,可能还特定于端口(地址=5005)。

于 2019-06-28T15:18:56.500 回答
2

简单的解决方案:您应该添加src/test/resources/logback.xml

<configuration debug="false">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <pattern>%date{HH:mm:ss.SSS} %highlight(%-5level)
            %gray(%logger{90}) %X{X-ApplicationId} %msg%n
        </pattern>
    </encoder>
</appender>
于 2021-03-26T13:41:57.553 回答
2

确实遇到了与我尝试在运行 JAVA = 1.8 的 Windows 10 环境中编译设置为 1.7 的 maven 项目相同的问题。

我通过将 java 版本从 1.7 更改为 1.8 来解决它,如下所示。

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
于 2018-06-15T08:10:48.277 回答
1

添加配置文件后,我能够删除此错误:

<profile>
            <id>surefire-windows-fork-disable</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <configuration>
                                <forkCount>0</forkCount>
                                <useSystemClassLoader>false</useSystemClassLoader>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>

似乎这是关于 maven surefire forks 的 Windows 问题

于 2021-02-02T07:49:16.137 回答
1

使用 maven test 运行单元测试时,我遇到了同样的问题。尝试更改安全版本,但它不起作用。最后设法解决如下: 早期:(当问题发生时):javac 来自 jdk 1.8 java 指向来自 jdk 1.11 的 java bin 当前:(当问题得到解决时):javac 和 java 都指向来自 jdk 1.8 的垃圾箱

问候泰迦。

于 2020-02-02T06:24:29.103 回答
1

我的情况与Chad相似,但找到了不同的答案。

根据插件文档,您不能使用${...}in,<argLine>因为 Maven 会在 surefire 插件(或任何其他插件)之前选择它进行替换。

从 2.17 版本开始,该插件支持@{...}而不是${...}用于属性替换。

例如,替换这个

<argLine>XX:MaxPermSize=1024m ${moreArgs}</argLine>

有了这个

<argLine>XX:MaxPermSize=1024m @{moreArgs}</argLine>
于 2019-12-02T16:31:23.240 回答
1

我尝试了所有提供的解决方案(分叉、系统加载器、更多内存等),但没有任何效果。

环境:在 gitlab ci 环境中构建失败,在 docker 容器中运行构建。

解决方案:我们在 2.20.1 版本中使用了 surefireplugin,升级到 2.21.0 或更高版本(我们使用 2.22.1)解决了这个问题。

原因SUREFIRE-1422 - surefire 使用了命令ps,该命令在 docker 环境中不可用并导致“崩溃”。此问题已在 2.21.0 或更高版本中修复。

感谢另一个问题的答案:https ://stackoverflow.com/a/50568662/2970422

于 2019-04-18T08:42:10.200 回答
1

在 Windows(OpenJDK11、Maven 3.6.0、SUREFIRE 3.0.0-M1)上,我得到了根本原因:

# Created at 2018-11-14T14:28:15.629
OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000006c7500000, 522190848, 0) failed; error='The paging file is too small for this operation to complete' (DOS error/errno=1455)

并通过增加页面文件大小来解决,例如这样

于 2018-11-16T00:36:51.473 回答
1

以上都试过了,还是不行。以下解决方案对我有用:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
    <argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>

于 2018-11-20T02:39:05.010 回答
1

我在 Ubuntu 机器上构建 Jenkins 时遇到了这个问题。

/var/log/syslog报道Out of memory: Kill process 19557 (java) score 207 or sacrifice child

因此我给了 Ubuntu 机器更多的交换空间。从那时起,问题就消失了。

于 2016-09-20T18:01:25.053 回答
0

在我的测试类中的一个静态成员变量调用了一个创建对象的方法(在整个类的测试用例中使用)之后,我遇到了这个错误,并且该方法导致了异常。

// Object created inside test class by calling a static getter.
// Exception thrown in getter:
private static Object someObject = SomeObject.getObject(...);

// ... <Object later used in class>

一些修复包括在每个测试用例中重新创建对象并相应地捕获任何异常。或者通过在 @BeforeTest 方法中初始化对象并确保它正确构建。

于 2015-05-13T19:47:03.927 回答
0

我在运行测试时将大量 XML 记录到控制台的应用程序中遇到了同样的问题。我认为这个问题与测试分支将其控制台日志发送到主 maven 线程以输出到屏幕的方式有关。

我通过在我的测试 logback 文件中将违规类的日志记录设置为 WARN 来解决这个问题。

例如 logback-test.xml

<configuration debug="true">
  <include resource="org/springframework/boot/logging/logback/defaults.xml" />
  <include resource="org/springframework/boot/logging/logback/console-appender.xml" />

  <logger name="com.foo.ClassWithLotsOfXmlLogging" level="WARN" />

  <root level="INFO">
    <appender-ref ref="CONSOLE"/>
  </root>
</configuration>
于 2020-09-30T07:20:21.357 回答
0

我使用文件夹名称作为test&demo,所以它给出了这个问题(VM 终止但没有正确告别。VM 崩溃或 System.exit 调用),但是当我将文件夹名称作为test_demo时,它解决了这个问题。(这个问题与带有“&”符号的 Windows 操作系统。)

将“&”替换为“_”

此问题可能会导致文件夹名称中有一些特殊符号或额外空格。

于 2020-01-21T10:20:12.420 回答
0

由于完全不同的问题,这也可能发生。例如,在我的例子中,我们的 Jenkins 构建在无缘无故地执行测试时间歇性地失败。

我筛选了我们的测试以找到任何发生System.exit()但没有。

经过更多挖掘后,我发现这可能是由于 JDK 错误而导致的,该错误可能导致了这种回归。

JDK-6675699

我仍在努力在我们的构建中进行此修复,将回来并再次更新线程。

于 2017-07-06T21:59:39.580 回答
0

发生在我身上:如果您的项目依赖于 docker 机器或/和数据库来成功构建,那么请首先检查您的数据库实例是否已启动并且您的 docker 也已启动,因为可能有一些单元测试在后台运行...检查尤其是在启动笔记本电脑之后..希望对某人有所帮助

于 2021-04-28T09:45:05.443 回答
0

最近travis 终止了测试的执行(没有更改任何相关内容(并且在开发人员机器上成功构建!)),因此BUILD FAILURE。原因之一是这个(见@agudian 回答):

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

(因为确实调用了测试类System.exit(-1))。

  1. 相反,使用简单的return语句会有所帮助。

  2. 为了让 travis 再次开心,我还不得不添加<argLine>@xiaohuo 提供的surefire 参数( )。(另外,我必须删除-XX:MaxPermSize=256m才能在我的一个桌面上构建)

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

有关更多背景信息,请阅读我们何时应该在 Java 中调用 System.exit

于 2017-03-24T09:21:14.837 回答
0

就我而言,这是我调用 System.exit(0) 的代码。

以下是 te 文档中关于它的摘录:

Surefire 不支持任何时候调用 System.exit() 的测试或任何引用的库。如果他们这样做,它们与 Surefire 不兼容,您可能应该向库/供应商提出问题。

于 2019-03-28T17:26:10.073 回答
0

在我的情况下,通过设置 MAVEN_OPTS 来增加内存有助于:

set MAVEN_OPTS=-Xmx1024m
于 2019-11-13T00:46:06.780 回答
0

这可能是由于内存不足造成的。确保在运行 mvn 时没有任何应用程序在后台运行。就我而言,Firefox 在后台运行,内存使用率很高。

于 2018-01-07T17:59:59.717 回答
0

在将 Maven 从 2.6.3 更新到 2.8.4 后,我遇到了同样的问题。问题是分叉的 JVM 因内存不足而崩溃,因此只需在 Surefire 插件配置中将内存从 1024Mb 增加到 2048Mb 即可解决问题

        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <!--suppress UnresolvedMavenProperty -->
                <argLine>${argLine} -Dfile.encoding=UTF-8 -Xmx2048m</argLine>
            </configuration>
        </plugin>
于 2022-02-22T10:54:52.333 回答
0

这对我有用。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
    <argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
于 2022-01-20T08:48:45.477 回答
0

我也经历过这种情况——但就我而言,我为黄瓜写了一个自定义钩子

public class MappingFormatter implements gherkin.formatter.Formatter {

...

我的一种方法是产生一个空指针异常,这导致surefire退出而不记录错误。

于 2016-10-27T21:26:40.353 回答
0

这肯定会奏效......

在 POM 文件中添加以下行并进行构建。

<plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
          <configuration>
            <trimStackTrace>false</trimStackTrace>
            <includes>
              <include>**/*Test.class</include>
            </includes>
          </configuration>
        </plugin>
于 2018-03-21T06:31:05.750 回答
0

我的决议是更改Jenkinsfile中提到的超时90 to 120.

pipeline {
    agent { label projectName }

options {
    disableConcurrentBuilds()
    buildDiscarder(logRotator(numToKeepStr:'5'))
    timeout(time: 90, unit: 'MINUTES')
}

谢谢,萨

于 2021-09-15T11:24:39.637 回答
0

当我遇到此错误时,这是​​由于我的打开文件 ( ulimit -n) 的 ulimit 太低。它(不知何故)设置为仅 256:

% ulimit -n
256

增加限制后,错误消失了:

% ulimit -n 3072
% ulimit -n     
3072

您的系统可能不允许将限制设置得如此之高。例如,当我尝试使用更大的数字时会发生这种情况:

% ulimit -n 3073
ulimit: setrlimit failed: invalid argument

或者这可能低于您现有的限制,您可能面临不同的根本原因。

于 2016-07-26T23:32:12.350 回答
0

就我而言,我忘记在 pom 中添加依赖项:

      <dependency>
          <groupId>org.aspectj</groupId>
          <artifactId>aspectjweaver</artifactId>
          <version>1.8.5</version>
      </dependency>

只要确保您选择了正确的版本(至于今天 1.8.9 是最新的)

于 2016-09-02T08:26:54.293 回答
0

就我而言,这个问题与工作空间路径有关,它太长了。所以我做了一个路径重构,这解决了我的问题。

于 2016-02-23T13:41:55.040 回答
0

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

简而言之,我的解决方案是:

  • 添加-B(批处理模式)
  • 添加 JVM 参数-Djansi.force=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.multiModuleProjectDirectory=[path_to_myproject] - Dfile.encoding=UTF-8 -Djansi.force=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.multiModuleProjectDirectory=[path_to_myproject] - Dfile.encoding=UTF-8 -Djansi.force=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 args”传递给“mvn.cmd”以使其变得更好。

我猜是这样的:有没有办法通过命令行将 jvm args 传递给 maven?


一点背景:

自最新版本的maven(3.x +)以来,我反复遇到这个问题。我在这里尝试了许多解决方案,有时很幸运,有时却没有。

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

但是有一些常数,当我遇到这个问题时:

  • 始终在 Windows 上,本地
  • 总是有很多控制台输出。
  • 并非团队的所有开发人员都在给定项目上遇到错误
  • 詹金斯构建会通过
  • *IT 测试中的大量控制台输出(故障安全集成测试)

关键的发现是我注意到在 Eclipse 中(无论有没有嵌入式 maven 版本)一个完整的 maven 构建(全新安装)都可以工作。

所以我弄清楚了 Eclipse 正在使用哪个命令(感谢:如何获取 Eclipse 运行配置的命令行?

从那里,我能够确定解决方案是。

查看人们所说的其他答案

那里显然有一个错误。要么在 Maven 中,要么在 windows 控制台中,要么在 Jansi lib 中,要么在这些组件的集成中。

于 2021-03-25T14:05:38.780 回答
0

对我有用的解决方案,设置:<forkCount>0</forkCount>

IE

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <forkCount>0</forkCount> 
    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
  </configuration>
</plugin>
于 2022-02-04T11:40:51.127 回答
-1

可能是因为您在项目中应用了一些更改并且没有更新它们的所有引用。

在我的情况下,我收到了这个错误,因为我在我的项目中更新了包名称,但我忘记在 TestNG.xml 文件中更新它们的引用。通过更正它,我解决了这个错误。

于 2014-10-16T07:37:16.603 回答
-3

“原因:java.util.concurrent.ExecutionException:java.lang.RuntimeException:分叉的虚拟机在没有正确告别的情况下终止。虚拟机崩溃或调用 System.exit?”

如果您使用不兼容的 java 版本,则可能会出现此问题。喜欢使用新版本的java,而代码支持其他版本。

于 2018-04-24T23:41:22.913 回答
-8

分叉的虚拟机没有正确告别就终止了。VM 崩溃或调用 System.exit

防止此错误的方法是以管理员身份运行 IDE。

于 2017-01-17T09:57:23.330 回答
-50

对我来说,它适用于

mvn clean install -DskipTests -e
于 2014-12-17T09:38:21.773 回答