jacoco没有生成执行文件:Skipping JaCoCo execution due to missing execution data file.

配置JaCoCo插件时遇到执行文件未生成,导致无法创建覆盖率报告。通过检查控制台输出,发现Surefire插件的参数配置不正确。更新Surefire配置,设置`useSystemClassLoader`为`false`,`forkMode`为`once`,`reuseForks`为`true`,最终成功生成了覆盖率报告。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置

配置jacoco 插件时,主pom中配置如下

<plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.2</version>
                    <executions>
                        <execution>
                            <id>jacoco-initialize</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <!--这个report:对代码进行检测,然后生成index.html在target/jacoco-ut/index.html中可以查看检测的详细结果-->
                        <execution>
                            <id>jacoco-site</id>
                            <phase>test</phase>
                            <!--<phase>package</phase>写上test的时候会自动出现jacoco-ut文件夹,而不需执行下面的jacoco:report步骤,推荐-->
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>target/jacoco.exec</dataFile>
                                <outputDirectory>target/jacoco-ut</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

在每个子pom中配置

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
            </plugin>

运行mvn test 或在 maven Projects -> Lifecycle中双击test后,没有生成覆盖率报告。

问题

查看运行结果,最开始发现是因为没有生成执行文件,所以查了很多博文,
jacoco没有生成执行文件,发现都没办法解决

[INFO] --- jacoco-maven-plugin:0.8.2:report (jacoco-site) @ manager ---
[INFO] Skipping JaCoCo execution due to missing execution data file.

解决

最后发现还是使用 Surefire 配置破坏 JaCoCo 代理,但是不是以上原因,查看了控制台输出,发现以下提示

[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ manager ---
[WARNING] The parameter forkMode is deprecated since version 2.14. Use forkCount and reuseForks instead.

最后在主pom和每个子pom都添加了以下配置

<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.21.0</version>
                    <configuration>
                        <useSystemClassLoader>false</useSystemClassLoader>
                        <forkMode>once</forkMode>
                        <reuseForks>true</reuseForks>
                        <testFailureIgnore>true</testFailureIgnore>
                    </configuration>
                </plugin>

重新执行,终于有覆盖率报告了!!!!!
(解决后才发现原来已有博主有提到这种原因啦,贴个链接
surefire破坏jacoco配置

我在idea中点击右侧的maven标志,并进行run maven bulid时报错:[INFO] --- jacoco:0.8.7:report (report) @ pureedgesim --- [INFO] Skipping JaCoCo execution due to missing execution data file. [INFO] [INFO] --- jar:3.2.0:jar (default-jar) @ pureedgesim --- [WARNING] JAR will be empty - no content was marked for inclusion! [INFO] [INFO] --- source:3.2.1:jar-no-fork (attach-sources) @ pureedgesim --- [INFO] No sources in project. Archive not created. [INFO] [INFO] --- javadoc:3.2.0:jar (attach-javadocs) @ pureedgesim --- [INFO] [INFO] --- install:3.1.2:install (default-install) @ pureedgesim --- [INFO] Installing D:\Users\KEN\K\testtest\PureEdgeSim-master\PureEdgeSim-master\pom.xml to C:\Users\KEN\.m2\repository\com\mechalikh\pureedgesim\5.3.0\pureedgesim-5.3.0.pom [INFO] Installing D:\Users\KEN\K\testtest\PureEdgeSim-master\PureEdgeSim-master\target\pureedgesim-5.3.0.jar to C:\Users\KEN\.m2\repository\com\mechalikh\pureedgesim\5.3.0\pureedgesim-5.3.0.jar [INFO] [INFO] --- deploy:3.1.2:deploy (default-deploy) @ pureedgesim --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.920 s [INFO] Finished at: 2025-03-27T17:35:53+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.1.2:deploy (default-deploy) on project pureedgesim: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::url parameter -> [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 Process finished with exit code 1
03-28
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值