Using Maven and JaCoCo for Consolidated Multi-Module Code Coverage Reports

Authored byNirmal Son Apr 14, 2017 in Topic Technology
Keyword Cloud

Subscribe to email updates


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:

  • Add JaCoCo plugin to the Parent POM. If specific modules don’t have to be included in the test coverage, change the plugin definition based on specific projects as required.
  • Create a submodule to append all results from JaCoCo using the Ant task.
  • Specify the Ant command from Maven using the Maven Antrun plugin.
  • Configure the JaCoCo Ant task configuration process with the necessary information such as location of build, class, source or generated-source directories.
  • From the Antrun plugin, define the reporting tasks. Specify locations to store the JaCoCo report execution data. This information can be covered for each submodule within each project.
  • Create a reporting structure based on requirements, such that each group of elements will contain information only on the specific set of modules.

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.

This article was authored by Nirmal Suthar, who is a Lead Software Engineer at Zymr.



Leave a Reply

Contact Us

Request a Consultation

Please prove you are human by selecting the Star.

Smartsourcing: A guide to selecting an Agile Development Partner

Smartsourcing is a brief guide to the world of modern technology partnerships. It was developed through a collaborative effort of top Zymr executives as we uncovered a gap in the market between the perception of what outsourcing used to be, and how leading technology innovators are leveraging this globalized approach to value generation. Read this guide to learn...

  • Key factors to consider for your development strategy
  • Popular destinations with a track record of high quality services
  • Selection criteria to narrow your shortlisted vendors

Get access to Smartsourcing eBook

 30 days 3 Months 1 year Still exploring

Register below to download your free eBook

Register below to download your free White Paper

Register below to download your free Guide

Register below to download your full Case Study

Please prove you are human by selecting the Tree.

Register below to download your Healthcare Cloud Stack

Register below to download your Microservices eBook