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

Thanks. Attached is the log : sonar_build_log.zip (495.6 KB)

To remind you the setup is :
image

Ah, my apologies, my suggested mechanism for enabling debug logging won’t affect running maven within a later pipeline step. You’ll need to enable debugging within the maven task. Can you add the debug (-X) parameter to the maven command in that task? And then please supply the log.

Here is the log with debug (-X) : sonar_log_debug.zip (2.0 MB)
Same password.

Thank you.

Thank you. Can you also supply the coverage file that was used by this analysis? /home/vsts/work/1/s/CCReport43F6D5EF/jacoco.xml

One thing I noticed which seems odd: you are passing the coverage report in to the maven command from outside, via -Dsonar.coverage.jacoco.xmlReportPaths=/home/vsts/work/1/s/CCReport43F6D5EF/jacoco.xml

Whereas you’re running JaCoCo within the build again, apparently only generating .exec format files, and then not recreating an aggregate XML file. Somewhere in here, I suspect, lies your issue.

Sure, here it is : Code Coverage Report_5755_2.zip (861.3 KB)

Well here is the config, nothing fancy :

image

Is there anything under Advanced passing additional parameters to maven?

I see this in your log, and there are a number of related parameters un-accounted for in your screenshots:

2020-09-09T19:55:37.4592008Z [command]/usr/share/apache-maven-3.6.3/bin/mvn -f /home/vsts/work/1/s/pom.xml -Ddocker.tag.name=1.4.5755 -X clean verify -Dsonar.jacoco.reportPaths=/home/vsts/work/1/s/CCReport43F6D5EF/jacoco.exec -Dsonar.coverage.jacoco.xmlReportPaths=/home/vsts/work/1/s/CCReport43F6D5EF/jacoco.xml org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar

The parameter -Dsonar.jacoco.reportPaths should no longer be passed as it was deprecated and ultimately removed. And I remain curious why -Dsonar.coverage.jacoco.xmlReportPaths=/home/vsts/work/1/s/CCReport43F6D5EF/jacoco.xml is being passed in from outside; the JaCoCo XML report should really be generated within this build.

Nothing within Advanced paramters.

I don’t have control over what is passed from the Maven Task (it is Azure DevOps native task for Maven).

I know about the deprecated stuff but note that one day this config already worked. Plus we are getting the Jacoco code coverage. Just not in SonarQube.

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.