Recommended jacoco config not producing reports: Skipping JaCoCo execution due to missing execution

We have a multimodule java maven project like this:

parent

  • child 1
  • child 2
  • common

We would like a code coverage report per sub module (not one global one for the entire project).

this page: Java test coverage | SonarQube Server Documentation

Says we just need to add this to the parent pom:

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.8.13</version>
                        <executions>
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>report</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <configuration>
                                    <formats>
                                        <format>XML</format>
                                    </formats>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>

When we run mvn test or mvn clean verify in the parent dir, we get this:

[INFO] — jacoco:0.8.13:prepare-agent (prepare-agent) @ my-service —
[INFO] argLine set to -javaagent:C:\Users\me\.m2\repository\org\jacoco\org.jacoco.agent\0.8.13\org.jacoco.agent-0.8.13-runtime.jar=destfile=C:\Users\me\dev\my-service\target\jacoco.exec

The issue is my-service is the root (parent) dir, and there is no target directory, only the sub modules contain code and target directories.

So there do not seem to be any jacoco.exec generated

The sonar doc says:

“By default, the generated report will be saved under target/site/jacoco/jacoco.xml

But this dir does not exist.

If I push the above changes to the PR, it re runs the sonar pipeline, and in the output I see:

`[INFO] argLine set to -javaagent:/root/.m2/repository/org/jacoco/org.jacoco.agent/0.8.13/org.jacoco.agent-0.8.13-runtime.jar=destfile=/opt/atlassian/pipelines/agent/build/target/jacoco.exec`

`[INFO] --- jacoco:0.8.13:report (report) @ my-service ---`

`[INFO] Skipping JaCoCo execution due to missing execution data file.`

If we look in a target dir of a sub module, we see:

Mode                 LastWriteTime         Length Name                                                                                                                                                                                                                                                             
----                 -------------         ------ ----                                                                                                                                                                                                                                                             
d-----        15/05/2025     14:34                classes                                                                                                                                                                                                                                                          
d-----        17/06/2025     15:15                generated-sources                                                                                                                                                                                                                                                
d-----        17/06/2025     15:15                generated-test-sources                                                                                                                                                                                                                                           
d-----        29/05/2025     17:35                maven-archiver                                                                                                                                                                                                                                                   
d-----        29/05/2025     17:35                maven-status                                                                                                                                                                                                                                                     
d-----        17/06/2025     15:16                surefire-reports                                                                                                                                                                                                                                                 
d-----        29/05/2025     17:35                test-classes                            

There is no target dir in the parent.

If we instead run “mvn clean verify sonar:sonar” we DO see a directory which is:

parent/target/sonar/ which we dont get if we do mvn test or mvn verify. In this dir, we see some sub dirs like “ir” and “usfg2” but nothing which looks like a jacoco report.

any suggestions? We don’t really know jacoco, we had hoped that sonar would do code coverage. Using the config in the sonar docs doesn’t seem to work. We pay a lot for sonar, but are struggling to get it to work.

Hi,

You seem to have followed the directions for adding JaCoCo report generation to a single-module Maven project, not the directions for adding it to a multi-module Maven project.

 
HTH,
Ann

Hi, thanks for the reply. However, the doc says that you can use the single module solution directly in a multimodule solution without change. It says you only need to change it if you want an aggregated output, which we do not. Unless I am missing something?

For multi-module Maven projects, you configure the jacoco-maven-plugin in a profile in the parent pom just as in the single module case, above. By default, a separate coverage report will be generated for each module.

Hi,

Per the (multi-module) docs, emphasis mine:

For multi-module Maven projects, you configure the jacoco-maven-plugin in a profile in the parent pom just as in the single module case, above. By default, a separate coverage report will be generated for each module.

Per the (single-module) docs (emphasis mine):

By default, the tool generates XML, HTML, and CSV versions of the report. Here, we explicitly specify XML, since that is the only one we need for SonarQube Server.

It’s not clear to me where your expectation for .exec comes from, but we haven’t supported that format for several years now.

 
HTH,
Ann

Thanks for the reply, but Im not sure if it helps. We are using the exact documented config for jacoco for a multimodule project with separate (non aggregated) reports, but it doesnt work. There dont seem to be any jacoco artifacts generated, but we see from the logs that jacoco is running without error (although if we let it run in bitbucket pipelines there are warnings as identified in the original post). We dont really have any options or ways to get this to work.

Hi,

If you have deep questions about JaCoCo then you’ll need to ask them in the JaCoCo community. But what’s your command? Are you running this from the docs?

mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pcoverage

As I understand it, that runs the coverage -Profile (altho your snippet in the first post doesn’t actually include that part from the docs

Versus the docs:

The <profile> section of your pom.xml should look something like this:

<profile>
  <id>coverage</id>
  <build>
   <plugins>
    <plugin>

 
HTH,
Ann

Hi Ann, the profile is just a place holder which allows you to switch on and off the corresponding section, its not needed and has no effect on the POM other than to enable or disable that section. I actually have it in a profile based on environment (so it will only run on non prod envs), but to rule this out I also took it out of the profile to make sure its included. It really doesnt make a difference with or without a profile.

The jacoco is explicitly configured for sonar, the Jacoco community wont be able help much with this this, but I can try them.

The command line is just for manually testing it locally, the real use is when sonar does the sonar build in the bitbucket pipeline. Looking at the logs of the pipeline running with the pom I have documented here, it doesnt work.

I have read every post I can find on this subject, looking for clues how to get sonar to work with jacoco, and most of them say that mvn clean verify sonar:sonar will cause the code coverage to be run. Ideed, jacoco is being run, just not working with sonar.

Ill try this tomorrow:

mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Pcoverage

But if it works it wont help much as it needs to work in the butbucket pipeline automatically, devs are not going to remember to hand run this every time they make a code change, and Indeed, we dont want to need to have to give every dev the sonar key.

We pay for sonar, is there any way to get support or to raise a support ticket?

Hi,

Commercial support is available. You should reach out to contact@sonarsource.com if you’re interested.

 
Ann

I can confirm that the above command does not result in any ouptput from jacoco. There is nothing related to jacoco in parent/target, nor in the child target directories.

I also tried adding the profile as directed:

<profiles>
    <profile>
        <id>coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.13</version>
                    <executions>
                        <execution>
                            <id>prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <formats>
                                    <format>XML</format>
                                </formats>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Hi,

Well, as stated, we’re not JaCoCo experts.

I Googled “Skipping JaCoCo execution due to missing execution data file.`” and found this.

At this point, I can only point you to what our docs say:

Typically, you would create a specific Maven profile for executing the unit tests with instrumentation and producing the coverage report only on demand.

In the most basic case, we will need to execute two goals: jacoco:prepare-agent, which allows coverage info to be collected during unit tests execution, and jacoco:report, which uses data collected during unit test execution to generate a report.

 
Good luck,
Ann