Dmytro Chyzhykov's Blog

Yet another programmer.

Skipping JaCoCo Execution Due to Missing Execution Data File

Sometimes, because of misconfiguration, JaCoCo Maven Plugin can stop working and begin notifying you about it with the following annoying message

1
2
3
4
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.1.201405082137:report (default-cli) @ project-name ---
[INFO] Skipping JaCoCo execution due to missing execution data file:/project-dir/target/jacoco.exec
[INFO] ------------------------------------------------------------------------

Let’s consider some common misconfiguration cases.

Forgot to prepare the JaCoCo agent

That means the you added no execution which prepares JaCoCo agent.
To start with, you might add the following default agent configuration excerpt:

1
2
3
4
5
6
<execution>
    <id>default-prepare-agent</id>
    <goals>
        <goal>prepare-agent</goal>
    </goals>
</execution>

And your default JaCoCo Maven Plugin configuration might look like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.1.201405082137</version>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>default-report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>default-check</id>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

It’s good to check the latest JaCoCo example project pom.xml to be in touch with the fresh default plugin configuration.

Broke the JaCoCo Agent with the Surefire configuration

Maven Surefire Plugin is used to execute unit tests during the test phase of the build lifecycle.
It’s included in project’s pom.xml implicitly, one way you can check this is by running the command at the project’s root

1
mvn help:effective-pom

and among other stuff you get the plugin with its default version for current Maven distribution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.4</version>
    <executions>
        <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
            </goals>
        </execution>
    </executions>
</plugin>
...

When you decide to configure the maven-surefire-plugin to meet your project’s custom needs, you might accidentally break the JaCoCo Agent. It can be broken either with the forkCount of 0

1
2
3
4
5
6
7
8
9
10
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        ...
        <forkCount>0</forkCount>   <!-- this line breaks JaCoCo Agent -->
        ...
    </configuration>
    ...
</plugin>

or forkMode of never. forkMode is deprecated since version 2.14

1
2
3
4
5
6
7
8
9
10
11
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        ...
        <!-- forkMode is deprecated since version 2.14 -->
        <forkMode>never</forkMode>  <!-- this line breaks JaCoCo Agent -->
        ...
    </configuration>
    ...
</plugin>

or both.

You can re-enable normal work of the JaCoCo Agent by:

  • specifying the forkCount of any reasonable positive integer
  • replacing the forkMode with the reuseForks.

The reuseForks indicates if forked VMs can be reused. If set to false, a new VM is forked for each test class to be executed. If set to true, up to forkCount VMs will be forked and then reused to execute all tests.

Here is an example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.17</version>
    <configuration>
        <forkCount>1</forkCount>
        <reuseForks>true</reuseForks>
    </configuration>
    <executions>
        <execution>
            <id>default-test</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Have a nice day.

Read also: - JaCoCo Maven Plug-in