Multi module JAVA Maven project Jacoco code coverage report setup required for sonarqube (cover Unit and Integration Test report)

Hi
Multi module JAVA Maven project Jacoco code coverage report setup for sonarqube (cover Unit and Integration Test report). Please help how to setup for pom.xml (plugins & configaration)

It works OOTB. You only need to add jacoco-maven-plugin in the main pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.2</version>
            <executions>
                <execution>
                    <id>jacoco-initialize</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

and install JaCoCo plugin on SonarQube server.

HI Adam,

Thanks for reply, i have one more [Unit test are running while build time and integration tests (IT) running on another server while running some functional test cases. I am copying that generated jacocIT.exec files to build server and i need to merge both together then need to send sonar dashboard. How can i configure this kind of situation.

I think you have to do the following steps:

  1. generate unit tests coverage on a main server
  2. generate integration tests coverage on an other machine
  3. send coverage from the other machine to the main server
  4. merge jacoco results
  5. execute only sonar analysis, and pass the merged jacoco report: mvn sonar:sonar -Dsonar.jacoco.reportPaths=/path/to/merged/jacoco.exec

I hope it works :slight_smile:

Hi Adam,

Is there a way by which I can only post the coverage reports (both unit and integration tests merged) to SonarQube without running the analysis.
Actually, I am running this in a Jenkins Pipeline where the Static Code Analysis would have happened in an earlier stage and its result posted to the SonarQube server. This stage runs before integration tests are run. At a later stage in the pipeline, when all the tests have executed and I have the merged coverage report, I want to post the coverage reports only without running the analysis again. Is it possible?
Any help in this regard will be appreciated.

-SH

Thanks

According to my current knowledge - no, it is impossible.

Please don’t forget to accept the solution.