/ Java

JaCoCo Multimodule Maven Configuration

We've created a simple dummy-project that demonstrates how to configure the JaCoCo code coverage library in a multi-module Maven project with integration-tests in order to get a complete coverage-report.


One of the problems with jacoco and maven is that coverage is only reported for code in the module in which the tests are located and not for the entire project as a whole. This means that the coverage-percent will be under-reported in many cases.


In this example class A in module-a calls class B in module-b which calls class C
in module-c. All the tests are located in module-a. With standard configuration class A is the only class that will get coverage in the jacoco report.

By using report-appending in jacoco we can fix this and get coverage for all the classes in the whole project and not just for the classes in the module where the tests resides.

Root pom.xml



Configuration of the jacoco maven plugin:

        <!-- Unit-tests -->
        <!-- Integration-tests executed with failsafe-plugin -->

Nested submodules

No further configuration is required if you only have one level of submodules.
In our example we have two levels of submodules for module-c.

 - module-a
 - module-b
 - module-c
     - module-c1

To get nested submodules to append to the report we have to override the jacoco properties
we specified in the root pom:


Notice that we need to traverse up to the folder of the root module in the file path.


Run sonar in a docker container
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube

Build the project with integration-tests and and publish to sonar
mvn clean install failsafe:integration-test sonar:sonar