首页 > 解决方案 > Jacoco 报告丢失

问题描述

我正在尝试为我的项目创建一份 jacoco 报告。该项目是 java 12 版本,jacoco-maven-plugin 是 0.8.5 版本。

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <executions>
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>post-unit-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

我启动了一个 mvn clean 站点

mvn clean install site

我得到:

[INFO] --- jacoco-maven-plugin:0.8.5:prepare-agent (pre-unit-test) @ bowling-game ---
[INFO] argLine set to -javaagent:/home/baptiste/.m2/repository/org/jacoco/org.jacoco.agent/0.8.5/org.jacoco.agent-0.8.5-runtime.jar=destfile=/home/baptiste/IdeaProjects/Bowling-Game/target/jacoco.exec

...
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ bowling-game ---
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.keywer.kata.bowling.game.frame.state.FrameStateTest
[INFO] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.064 s - in com.keywer.kata.bowling.game.frame.state.FrameStateTest
[INFO] Running com.keywer.kata.bowling.game.BowlingGameTest
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 s - in com.keywer.kata.bowling.game.BowlingGameTest
...
[INFO] --- jacoco-maven-plugin:0.8.5:report (post-unit-test) @ bowling-game ---
[INFO] Skipping JaCoCo execution due to missing execution data file.

我正在寻找报告,但实际上它没有被创建,原因是以下行:
[INFO] Skipping JaCoCo execution due to missing execution data file。

我忘记了什么?

标签: jacoco-maven-plugin

解决方案


我的项目是用 java 12 版本编写的,我启用了这样的预览功能。

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <configuration>
      <argLine>--enable-preview</argLine> <=== This line
    </configuration>
</plugin>

问题是 maven 无法生成 jacoco.exec。

感谢@Jacek Laskowski,我通过此评论找到了遮阳篷https://stackoverflow.com/a/23605812/8591625

我只是替换为

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <configuration>
       <argLine>${argLine} --enable-preview</argLine> <=== Here I adding ${argLine} in order to not override argument
    </configuration>
</plugin>

推荐阅读