The JaCoCo plugin for Maven only reports code coverage for tests run in a particular module rather than reporting coverage across modules. This can be an issue for multi-module projects where unit tests from one module test code in other modules. Some projects are set up with unit tests in a separate module all by themselves, making the JaCoCo code coverage reports nearly useless. No matter what setup you run, JaCoCo won’t report code coverage well for integration tests that run across modules.
There are a number of possible solutions to address this challenge. One of the most obvious solutions is to avoid having a separate module for unit tests, rather including unit tests in the appropriate module. That probably won’t get you the whole way and may be a significant refactoring project.
Maven users can also create a separate reporting module with dependencies. Use this module to create dependencies to all the modules you need for your coverage report. Make sure the module has access to the right files, and accurate location paths are included.
You can use an additional tool to make up for this deficit. Some possible solutions are SonarQube, Jenkins, and Arquillian.
Since the Maven JaCoCo plugin doesn’t support merging of subproject metrics into a single report file, a possible workaround solution is to use Ant with Maven. The task objectives with this approach can be summarized as follows:
Hopefully, this helps you find some solutions (or at least workarounds) to the multi-module code coverage reporting when using Maven and JaCoCo. By the end of the day, while testing teams like to aim for 100 percent test coverage, it’s also important to measure it and avoid unnecessary testing. This concern is even more critical for handling multiple modules in test coverage reporting. Make sure your Maven tool handles all the necessary conditions and paths nicely, thereby accurately ensuring 100 percent test coverage across multi-module projects.