Skip to content

MavenMultiModule

Marc R. Hoffmann edited this page Mar 14, 2016 · 25 revisions

Maven Multi-Module Builds

Support for Maven multi-module build is a long outstanding feature request for JaCoCo. This page tries to collect all information about this feature.

Related Feature Requests

Current Situation

The current JaCoCo Maven goals work on single modules only: Tests are executed within the module and contribute coverage only to code within the same module. Coverage reports are created for each module separately. There is no built-in support for cross-module coverage or combined reports for multiple modules.

Work-Arounds

  • The JaCoCo Ant report task allows to specify arbitrary exec file, class file and source file locations. This task can be embedded with the maven-antrun-plugin.
  • Use external tools for report generation like SonarQube.

Use Cases

There is a couple of use cases where code coverage needs to be determined across multiple modules:

  • Creation of structured, browseable report for multiple modules.
  • A report which shows the overall coverage figures (also check goals for overall coverage)
  • Tests are located in a module separate from the code under test (e.g. Eclipse/Tycho). In this case the execution data is created within another module than the code under test.
  • Integration tests might contribute code coverage to multiple modules.

More Aspects:

  • Separate vs. combined reports for different test test levels (unit, it)
  • Transitive coverage (e.g. test for A causes code coverage on B when A depends on B): this might be desirable or not

Implementation

Strategy: Aggregator

Using a aggregator module seems to be the natural solution as this directly reflects the project hierarchy. Unfortunately this approach comes with a number of drawbacks:

  • Aggregator goals are executed before its submodules. But to create a combined coverage report the submodules needs to be built and tested first.
  • Aggregator goals cannot be bound to a lifecycle phase, therefore must always be specified manually on the command line.
  • There is very limited documentation for aggregators, some sources suggest that aggregators are deprecated and should not be used.

Strategy: Module with Dependencies

This approach requires a separate module to create the coverage report. The report is created for all modules a dependency is declared on. From those projects exec files as well as class and source files are collected.

Web Links

Other Maven Goals Supporting Multi-Module Reports

TODO

Clone this wiki locally