Jacoco 0 code coverage since switching to xmlReportPaths

Hi everyone,

Since we updated SonarQube jacoco.reportPath is not used anymore so our code coverage is not calculated anymore.

I read a lot of existing topics about similar problems and a tutorial that is available at the page [Coverage & Test Data] Importing JaCoCo coverage report in XML format

The problem I have is that code coverage is 0 in SonarQube. Agregate reports are generated and in the logs I can see that they are imported
‘’’

build 26-Aug-2020 09:47:24 [INFO] Sensor JaCoCo XML Report Importer [jacoco]
build 26-Aug-2020 09:47:24 [INFO] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
build 26-Aug-2020 09:47:24 [INFO] Sensor JaCoCo XML Report Importer [jacoco] (done)

‘’’

I am using:

  • SonarQube ver 8.4.1
  • JaCoCo XML report importer ver 1.1.0

I have a multi module maven project with this simplified structure:

main pom.xml
module shared with its pom.xml
module containing tests with its pom.xml


my main pom.xml

    <sonar.sources>src/main</sonar.sources>
    <sonar.junit.reportPaths>target/surefire-reports</sonar.junit.reportPaths>
    <sonar.javascript.lcov.reportPaths>target/jest-coverage/lcov.info</sonar.javascript.lcov.reportPaths>
    <aggregate.report.dir>target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
    <sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
....
<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.5</version>
            <executions>
                <execution>
                    <id>prepare-jacoco-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <goals>
                        <goal>report-aggregate</goal>
                    </goals>
                    <phase>test</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

my shared module pom.xml

<properties>
    <sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>

my module containing tests pom.xml

<properties>
  <sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>
</properties>

I execute sonar:sonar in Bamboo. Part of the Bamboo log file that shows that the reports are found and imported:


The only error I see is
error	26-Aug-2020 09:47:41	Unable to publish artifact [cucumber-reports]: the source directory /atlassian/bamboo/home/xml-data/build-dir/CSC-CSCN9-SCC/target/cucumber-reports does not exist.

Result: 0% code coverage:

What is wrong with my configuration? Please let me know if you need more details.

Thanks
Dusan

Finally I found a solution. It was to create a new maven module ‘jacoco-reports’ where the reports will be aggregated.

parent pom.xml

...
<sonar.coverage.exclusions>jacoco-report/**</sonar.coverage.exclusions>
<aggregate.report.dir>../jacoco-report/target/site/jacoco-aggregate/jacoco.xml</aggregate.report.dir>
<sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir} 
</sonar.coverage.jacoco.xmlReportPaths>    
....
<modules>
<module>jacoco-report</module>
....
<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>
        </executions>
  </plugin>

in each sub-module (except jacoco-report submodule)

        <sonar.coverage.jacoco.xmlReportPaths>${basedir}/${aggregate.report.dir}</sonar.coverage.jacoco.xmlReportPaths>

in jacoco-report submodule

<dependencies>
    <dependency>
        each sub module that generate jacoco reports 
    ....
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.5</version>
            <executions>
                <execution>
                    <id>report</id>
                    <goals>
                        <goal>report-aggregate</goal>
                    </goals>
                    <phase>verify</phase>
                </execution>
            </executions>
        </plugin>

That’s it, hope this will help someone.

1 Like

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