jacoco 插件不适用于 sunfire 插件.. org.apache.maven.surefire.booter.SurefireBooterForkException

Posted

技术标签:

【中文标题】jacoco 插件不适用于 sunfire 插件.. org.apache.maven.surefire.booter.SurefireBooterForkException【英文标题】:jacoco plugin not working with sunfire plugin.. org.apache.maven.surefire.booter.SurefireBooterForkException 【发布时间】:2022-01-10 11:49:51 【问题描述】:

我想使用 jacoco 插件生成一个站点来显示我的覆盖率测试。但是当我将插件添加到插件时,它会给我 org.apache.maven.surefire.booter.SurefireBooterForkException,当我不使用 jacoco 插件时它不会出现。 这是我的pom:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.umfds.agl</groupId>
<artifactId>couvertureEtMutation</artifactId>
<version>0.0.1-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <junit-platform.version>5.7.0</junit-platform.version>
</properties>
<dependencies>
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.12.0</version>
    </dependency>

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>$junit-platform.version</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>$junit-platform.version</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>5.7.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.2</version>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <!-- attached to Maven test phase -->
                <execution>
                    <id>report</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我希望在 target/site/jacoco 中生成我的覆盖率报告。我在互联网上搜索并发现了许多类似的问题,但没有一个解决方案对我有用。但为了更清楚地了解我得到的错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test 
(default-test) on project couvertureEtMutation: There are test failures.
[ERROR] 
[ERROR] Please refer to C:\Users\tanku\Documents\L3\Semestre1\HAI501I(GenieLogiciele)\tp4\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] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C "C:\Users\tanku\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149\jre\bin\java -server -ea -XX:MaxPermSize=256m -Xmx4g -XX:-UseSplitVerifier $surefire.argLine -jar C:\Users\tanku\AppData\Local\Temp\surefire13202390967333438775\surefirebooter9706852401708371992.jar C:\Users\tanku\AppData\Local\Temp\surefire13202390967333438775 2021-12-04T13-02-20_823-jvmRun1 surefire13582094628762200674tmp surefire_04422354844095939650tmp"
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C "C:\Users\tanku\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149\jre\bin\java -server -ea -XX:MaxPermSize=256m -Xmx4g -XX:-UseSplitVerifier $surefire.argLine -jar C:\Users\tanku\AppData\Local\Temp\surefire13202390967333438775\surefirebooter9706852401708371992.jar C:\Users\tanku\AppData\Local\Temp\surefire13202390967333438775 2021-12-04T13-02-20_823-jvmRun1 surefire13582094628762200674tmp surefire_04422354844095939650tmp"
[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:669)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:282)
[ERROR]     at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1183)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1011)
[ERROR]     at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:857)
[ERROR]     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
[ERROR]     at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
[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:305)
[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:957)
[ERROR]     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
[ERROR]     at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
[ERROR]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
[ERROR]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]     at java.base/java.lang.reflect.Method.invoke(Method.java:567)
[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] -> [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/MojoExecutionException

向 sunfire 插件添加配置消除了错误,但没有帮助我生成一个站点来查看我的覆盖结果。

<configuration>
    <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
</configuration>

<configuration>
    <forkCount>0</forkCount>
</configuration>

Second result

【问题讨论】:

原因是这样的:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project couvertureEtMutation: There are test failures. 你的测试失败了......你必须看看你失败的测试......! 由于某种原因,使用 surefirebooter.jar 调用外部 JVM 失败。您可以在控制台中执行此命令并向我们显示输出吗? %USERPROFILE%\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149\jre\bin\java -server -ea -XX:MaxPermSize=256m -Xmx4g -XX:-UseSplitVerifier $surefire.argLine -jar %LOCALAPPDATA%\Temp\surefire13202390967333438775\surefirebooter9706852401708371992.jar %LOCALAPPDATA%\Temp\surefire13202390967333438775 2021-12-04T13-02-20_823-jvmRun1 surefire13582094628762200674tmp surefire_04422354844095939650tmp @khmarbaise 我所有的junit测试都很好,它们没有失败。显示它们的屏幕截图会有所帮助吗? @khmarbaise:在我看来,这与测试无关(正如发帖者所写,它们在代码覆盖不发挥作用时执行得很好)。我怀疑某处存在配置问题,真正的问题是分叉肯定失败:Error occurred in starting fork, check output in log @roccobaroccoSC 我在帖子中放了一个屏幕截图。 【参考方案1】:

你可以试试它是否适用于我的 jacoco 配置?

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>$jacoco.version</version>
    <executions>
        <execution>
            <id>pre-unit-test</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <destFile>$project.build.directory/coverage-reports/jacoco-ut.exec</destFile>
                <propertyName>surefireArgLine</propertyName>
                <excludes>
                    <exclude>$project.build.directory/classes/**/*Impl*.class</exclude>
                    <exclude>$project.build.directory/test-classes/**/*.class</exclude>
                </excludes>
            </configuration>
        </execution>
        <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <dataFile>$project.build.directory/coverage-reports/jacoco-ut.exec</dataFile>
                <outputDirectory>$project.reporting.outputDirectory/jacoco-ut</outputDirectory>
                <excludes>
                    <exclude>$project.build.directory/classes/**/*Impl*.class</exclude>
                    <exclude>$project.build.directory/test-classes/**/*.class</exclude>
                </excludes>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <excludes>
            <exclude>$project.build.directory/classes/**/*Impl*.class</exclude>
            <exclude>$project.build.directory/test-classes/**/*.class</exclude>
        </excludes>
    </configuration>
</plugin>

我也有properties:

<surefireArgLine />
<jacoco.version>0.8.2</jacoco.version>

【讨论】:

它给了我:--- jacoco-maven-plugin:0.8.2:report (post-unit-test) @ couvertureEtMutation --- [INFO] 由于缺少执行数据文件而跳过 JaCoCo 执行. 对此我感到很困惑。您使用的是哪个 Maven 版本?您是否在 Eclipse 中执行测试?如果是这样,也许可以直接从命令行尝试使用 maven:mvn clean package 应该执行您的测试和代码覆盖率。此时我怀疑 Eclipse 存在配置问题。 它不会让我构建失败,但不会生成站点。我会将整个结果的屏幕截图放到我的帖子中。 我在使用 Maven 设置代码覆盖率时遵循了这个tutorial。尝试使用单个虚拟测试创建一个全新的项目,然后从命令行执行mvn clean verify。代码覆盖率报告应在target 下的某处找到。 当示例运行时,您需要比较与您项目的pom.xml 的不同之处。

以上是关于jacoco 插件不适用于 sunfire 插件.. org.apache.maven.surefire.booter.SurefireBooterForkException的主要内容,如果未能解决你的问题,请参考以下文章

jenkins插件--Cobertura,JaCoCo,Emma-----

Sonar是否使用Jacoco插件进行代码覆盖

如何验证某些排除类和 jacoco 插件的最小覆盖率?

Jacoco Maven 插件 - 生命周期配置未涵盖插件执行

Tomcat7 Maven 插件和 JaCoCo

Cordova 插件不适用于 ionic