Jacoco code coverage from Maven doesn't work anymore (azure devops)

Maybe you have some environment variables defined (in “Variables,” the tab beyond Tasks in the pipeline)?

Do you have a log of when it worked, for comparison’s sake? Were you on the same version of SonarQube at the time?

Well the code is here :

// Apply argument for the JaCoCo tool, if enabled
if (typeof execFileJacoco != "undefined" && execFileJacoco) {
    mvnsq.arg('-Dsonar.jacoco.reportPaths=' + execFileJacoco);
}

if (summaryFile) {
    mvnsq.arg(`-Dsonar.coverage.jacoco.xmlReportPaths=${summaryFile}`);
}

It include both of them when Jacoco is enabled.

Regarding the old, I don’t have the log anymore. We have a retention of only 30 days.

Hello @Xoib

I had a look at your problem, and I was surprised to see that you have in fact only one JaCoCo report, containing everything, is it expected? Typically, there is one report per module, and you are not even required to provide the property (sonar.coverage.jacoco.xmlReportPaths), since the report importer will look at the default location (target/site/jacoco/jacoco.xml).

In addition, could you share the JaCoCo configuration of your pom:

<artifactId>jacoco-maven-plugin</artifactId>

It would help to investigate the problem further.

Thanks @Quentin for having a look!

I know having everything in one JaCoCo report is weird, especially as we are working with modules tree within the pom.xml…

Attached is the pom.xml of the root project, and the pom.xml of one of the modules : pom.xml.zip (2.6 KB)

I know having everything in one JaCoCo report is weird

Just to clarify, since it seems that you are not satisfied either by the current situation, is it something that you would consider changing? Or are you looking for a solution that would keep this single report? If it is the latter, what are the motivation to do so (cross module coverage?)?

I might have a few clues on how to make it work with the current setup, but I just want to make sure that you don’t prefer to change JaCoCo configuration before investigating further.

I am willing to do whatever it takes to get the code coverage on SonarQube.

Outside of the Azure Devops world, the situation you describe seems trivial to me.
Simply make sure to configure JaCoCo goals prepare-agent and report. For example on my test project, I simply added this code:

<profile>
  <id>coverage</id>
  <activation>
      <activeByDefault>true</activeByDefault>
  </activation>
  <build>
   <plugins>
    <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.5</version>
    <executions>
      <execution>
        <id>prepare-agent</id>
        <goals>
         <goal>prepare-agent</goal>
        </goals>
      </execution>
      <execution>
        <id>report</id>
        <goals>
         <goal>report</goal>
        </goals>
      </execution>
    </executions>
    </plugin>
   </plugins>
  </build>
</profile>

to the root pom and… that it. The coverage is correctly imported.
Every module will generate his own report, and it will be used for analysis, finding the report in the default directory.

By the way, this nice guide exists for basic JaCoCo setup, with project examples. In your case, you don’t even need to look at the multi-module part since you are not interested by cross-module coverage.

At this point, could you try to analyze your project with a local instance of Sonarqube? It would enable you to have more control over the analysis and identify more precisely where the issue comes from.

In the current pom.xml I sent to you, this is exactly the same (0.8.4 instead of 0.8.5)

 <profile>
        <id>coverage</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                    <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <goals>
                    <goal>report</goal>
                    </goals>
                </execution>
                </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

Well I tried with your 0.8.5 suggestion and it didn’t change.

The difference that I can see is that you have an extra goal (merge), and that at the end, sonar.coverage.jacoco.xmlReportPaths point to the report generated by this goal, and not the one of the module itself (ex: module1/target/site/jacoco/jacoco.xml).

You should make sure this property points to the correct report, by either providing it or not setting the property at all.

Interesting, I used a command line task instead of the native Maven task in Azure DevOps and it works :

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.