Chris Savory
Chris Savory

Reputation: 2755

SonarQube not reading Integration JaCoCo Test coverage in parent pom target directory of a multi-module project

I have followed the instructions for enabling Unit and Integration tests for our Sonar Project here: http://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Integration+Tests+for+Java+Project

My pom settings are almost identical to the settings given in this example: https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/code-coverage/combined%20ut-it/combined-ut-it-multimodule-maven-jacoco

parent pom settings:

        <profile>
        <id>code-coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <configuration>
                        <append>true</append>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default-prepare-agent</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-agent-for-it</id>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>default-report</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <excludes>
                                    <exclude>static/**/*.jar</exclude>
                                    <exclude>static/**/*.class</exclude>
                                </excludes>
                            </configuration>
                            </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

We have a specific module that will run the integration tests:

        <profile>
        <id>code-coverage</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco.version}</version>
                    <configuration>
                        <!-- The destination file for the code coverage report has to be set to the same value
                            in the parent pom and in each module pom. Then JaCoCo will add up information in
                            the same report, so that, it will give the cross-module code coverage. -->
                        <destFile>${project.basedir}/../target/jacoco-it.exec</destFile>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

I have configured Sonar to look for UT and IT: enter image description here

Unit tests are being reported fine, but not Integration tests. In the Bamboo logs I can see that sonar is looking for integration tests and unit tests in all the submodules, but when it gets to the parent module it never runs the JaCoCoSensor or the JaCoCoItSensor. Both of those Sensors are run for each of the module projects. I also noticed there is a JaCoCoOverallSensor run for each module project but not the parent project.

How do I get the JaCoCoItSensor to run for the parent project?

Upvotes: 1

Views: 1031

Answers (1)

Chris Savory
Chris Savory

Reputation: 2755

I added a few configuration properties and it started working.

parent pom.xml added:

<properties>
    ...
    <sonar.jacoco.itReportPath>${project.basedir}/../target/jacoco-it.exec</sonar.jacoco.itReportPath>
    <sonar.language>java</sonar.language>
</properties>

IT Tests module I changed:

<destFile>${sonar.jacoco.itReportPath}/../target/jacoco-it.exec</destFile>

To this:

<destFile>${sonar.jacoco.itReportPath}</destFile>

Upvotes: 1

Related Questions