Ubuntu中的Maven测试引发异常

时间:2018-10-31 17:44:14

标签: maven unit-testing maven-surefire-plugin

由于我不知道某个事件,因此在我的Ubuntu 18.04中无法再调用if coordinate not in specialCoordinates。 (自4月开始运行)。 mvn test或我尝试过的任何其他生命周期阶段都很好。

如果例如我在克隆到mvn install -DskipTests=true的Apache Commons IO的最新版本中运行mvn test,则显示

/home/reichelt/commons-io/

目标/保证报告包含很多重复

[ERROR] ExecutionException The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /home/reichelt/commons-io && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -Xmx25M -jar /home/reichelt/commons-io/target/surefire/surefirebooter6661636703131088733.jar /home/reichelt/commons-io/target/surefire 2018-10-31T18-30-50_926-jvmRun1 surefire4405197448341812663tmp surefire_1048154306090710821475tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.awaitResultsDone(ForkStarter.java:494)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.runSuitesForkPerTestSet(ForkStarter.java:441)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:293)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1149)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:978)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:854)
[ERROR]     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
[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:51)
[ERROR]     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
[ERROR]     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
[ERROR]     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
[ERROR]     at org.apache.maven.cli.MavenCli.execute(MavenCli.java:955)
[ERROR]     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
[ERROR]     at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
[ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]     at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR]     at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR] Caused by: org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /home/reichelt/commons-io && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -Xmx25M -jar /home/reichelt/commons-io/target/surefire/surefirebooter6661636703131088733.jar /home/reichelt/commons-io/target/surefire 2018-10-31T18-30-50_926-jvmRun1 surefire4405197448341812663tmp surefire_1048154306090710821475tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:671)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:533)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.access$600(ForkStarter.java:115)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter$2.call(ForkStarter.java:429)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter$2.call(ForkStarter.java:406)
[ERROR]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[ERROR]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[ERROR]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[ERROR]     at java.lang.Thread.run(Thread.java:748)

我尝试过的任何其他项目都显示出类似的行为。

我尝试下载maven 3.5.4,将其解压缩,通过# Created on 2018-10-31T18:31:48.243 Error: Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter 将其添加到路径中并运行较新的版本,但这并没有改变任何内容(而export PATH=/home/reichelt/Downloads/apache-maven-3.5.4-bin/apache-maven-3.5.4/bin:$PATH可以正常工作并显示较新的版本版)。 Maven 3.5.0也是如此。

Maven error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher建议设置mvn -versionexport M3_HOME=/usr/share/maven会有所帮助,但不幸的是,它没有帮助。

我尝试删除export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/,但不幸的是,这也无济于事。

使用~/.m2在docker容器中运行并运行

docker run -it ubuntu

产生相同的行为,所以这似乎不仅仅是我的安装问题。

运行apt update apt install -y openjdk-8-jdk maven git mvn -version git clone https://github.com/apache/commons-io.git cd commons-io/ mvn test

docker run -it fedora bash

运行测试出乎意料。

有人知道如何解决此问题/解决该问题吗?

编辑 就像该消息所暗示的那样,yum install java-1.8.0-openjdk.x86_64* yum install wget wget http://ftp-stud.hs-esslingen.de/pub/Mirrors/ftp.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz tar -xvf apache-maven-3.5.4-bin.tar.gz yum install git export PATH=/apache-maven-3.5.4/bin:$PATH mvn -version git clone https://github.com/apache/commons-io.git cd commons-io/ mvn test 似乎是一个问题,无法找到。 https://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html描述了surefire可以由引导程序jar中的隔离类加载器或仅清单的jar使用。似乎默认情况下,我使用的是清单清单的jar,其中包含以下内容:

ForkedBooter

这对我来说似乎不错:Manifest-Version: 1.0 Class-Path: file:/home/reichelt/.m2/repository/org/apache/maven/surefi re/surefire-booter/2.21.0/surefire-booter-2.21.0.jar file:/home/reich elt/.m2/repository/org/apache/maven/surefire/surefire-api/2.21.0/sure fire-api-2.21.0.jar file:/home/reichelt/.m2/repository/org/apache/mav en/surefire/surefire-logger-api/2.21.0/surefire-logger-api-2.21.0.jar file:/home/reichelt/commons-io/target/test-classes/ file:/home/reich elt/commons-io/target/classes/ file:/home/reichelt/.m2/repository/jun it/junit/4.12/junit-4.12.jar file:/home/reichelt/.m2/repository/org/h amcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar file:/home/reichelt/. m2/repository/org/apache/maven/surefire/surefire-junit4/2.21.0/surefi re-junit4-2.21.0.jar Main-Class: org.apache.maven.surefire.booter.ForkedBooter 很好,并且包含/home/reichelt/.m2/repository/org/apache/maven/surefire/surefire-booter/2.21.0/surefire-booter-2.21.0.jar的类文件。

通过添加

org.apache.maven.surefire.booter.ForkedBooter

到pom,再次运行构建。这似乎是不使用<useSystemClassLoader>true</useSystemClassLoader> <useManifestOnlyJar>false</useManifestOnlyJar> 的解决方案。尽管这是一种解决方法,但我仍然想了解:我可以进一步调试此问题,以找到在当前的Ubuntu上不起作用的原因吗?由于它不能与其他Maven版本一起使用(即使在新的Ubuntu Docker容器中也可以),但在Fedora容器上也可以使用,因此我认为原因某种程度上与Ubuntu默认配置有关。

2 个答案:

答案 0 :(得分:4)

有趣的故事:确实,这是一个OpenJDK更新问题。

我通过sudo zcat /var/log/apt/history.log.1.gz | less阅读了我的上一个历史记录(取决于logrotating,它是0.1,可以是其他任何东西)。这表明今天早上运行了更新:

Start-Date: 2018-10-31  10:38:04
Commandline: /usr/bin/unattended-upgrade
Upgrade: openjdk-8-jdk:amd64 (8u181-b13-0ubuntu0.18.04.1, 8u181-b13-1ubuntu0.18.04.1), openjdk-8-jre:amd64 (8u181-b13-0ubuntu0.18.04.1, 8u181-b13-1ubuntu0.18.04.1), openjdk-8-jdk-headless:amd64 (8u181-b13-0ubuntu0.18.04.1, 8u181-b13-1ubuntu0.18.04.1), openjdk-8-jre-headless:amd64 (8u181-b13-0ubuntu0.18.04.1, 8u181-b13-1ubuntu0.18.04.1)
End-Date: 2018-10-31  10:38:09

因此由于某种原因,OpenJDK 8u181似乎与maven 3.5.2和surefire不兼容。由于已经安装了软件包升级,因此我再次使用sudo apt install openjdk-8-jdk=8u162-b12-1 openjdk-8-jre=8u162-b12-1 openjdk-8-jdk-headless=8u162-b12-1 openjdk-8-jre-headless=8u162-b12-1进行了降级。现在测试再次起作用。

https://www.oracle.com/technetwork/java/javase/8u-relnotes-2225394.html中,Java 8u171、8u172和8u181似乎没有包含更新,这些更新使得使用sureman-only罐的surefire不可能实现,但我只是在上面略过一眼,并没有深入探究该错误。报告。

编辑,该错误已在OpenJDK上报告:https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911925

编辑2 ,该错误已在Java 1.8.0_191中修复,并且mvn测试再次正常运行。

答案 1 :(得分:1)

今天遇到了同样的问题。不确定最好的长期修复方法,但是将maven-surefire-plugin的forkCount设置为0似乎已经为我修复了。不幸的是,这可能会使测试花费更长的时间。

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

希望有帮助。