1

I am using jacoco-maven-plugin to generate coverage report and using sonar-maven-plugin plugin to upload the report to SonarQube.

I am having below multi-module structure. BitBucket Project

mmproject
|
|---department-service
|
|---employee-service
|
|---component-test(This is for both the above services, code coverage for Controller)

I am using report-aggregate goal in pom.xml of component-test to merge the coverage report of employee-service, department-service and component-test module.

From component-test module.

           <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6</version>
                <configuration>
                    <excludes>
                        <exclude>com/jigarnaik/mmproject/*/model/*/**</exclude>
                        <exclude>com/jigarnaik/mmproject/*/config/*/**</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <id>report</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report-aggregate</id>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                        <phase>verify</phase>
                    </execution>
                </executions>
            </plugin>

And below is the content of parent pom.

<properties>
        <java.version>11</java.version>
        <swagger.version>2.9.2</swagger.version>

        <sonar.language>java</sonar.language>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/component-test/target/site/jacoco-aggregate/jacoco.xml
        </sonar.coverage.jacoco.xmlReportPaths>
        <sonar.java.binaries>${project.basedir}/target/classes</sonar.java.binaries>
        <sonar.java.test.binaries>${project.basedir}/target/test-classes</sonar.java.test.binaries>
        <sonar.exclusions>**/Application.java,**/model/*</sonar.exclusions>
    </properties>
    ...
    ...
          <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6</version>
                <configuration>
                    <excludes>
                        <exclude>com/jigarnaik/mmproject/*/model/*/**</exclude>
                        <exclude>com/jigarnaik/mmproject/*/config/*/**</exclude>
                        <exclude>com/jigarnaik/mmproject/**/Application.java</exclude>
                    </excludes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Jacoco coverage report which is more then 80% however when I see it on SonarQube the coverage is less then 50%. It's basically not showing coverage for any of the controller which is in my component-test module.

Am I missing something over here?

component-test coverage report - which is merged already and as expected.

SonarQube coverage which is missing coverage for both the Controller

Jigar Naik
  • 1,946
  • 5
  • 29
  • 60

0 Answers0