A custom Maven plugin that generates a textual tree-like coverage report from JaCoCo's execution data files, displaying coverage metrics (Class %, Method %, Branch %, Line %) for packages, source files, and the entire project.
- Reads coverage data from
jacoco.exec
files - Analyzes class files from the project's build output directory
- Outputs a hierarchical console-based report with coverage metrics
- Tree-like package structure visualization with collapsible paths
- Instant visibility of coverage metrics during build
- Multi-module project support with option to defer reporting until the end
- Automatic scanning for
jacoco.exec
files across modules - Support for custom JaCoCo execution file patterns
- Combined weighted coverage score based on customizable weights
- Exclude target directory to ignore generated files
- Maven 3.x
- JaCoCo plugin configured in your project to generate
jacoco.exec
Add the plugin to your project's pom.xml:
<build>
<plugins>
<plugin>
<groupId>io.github.svaningelgem</groupId>
<artifactId>jacoco-console-reporter</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<goals>
<goal>report</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run the plugin after tests:
mvn verify
Ensure the JaCoCo plugin has executed beforehand to generate jacoco.exec.
Parameter | Description | Default Value |
---|---|---|
jacocoExecFile |
Path to the JaCoCo execution data file | ${project.build.directory}/jacoco.exec |
classesDirectory |
Directory containing compiled classes | ${project.build.outputDirectory} |
deferReporting |
Defer reporting until the end (for multi-module projects) | true |
showFiles |
Whether to show individual source files in the report | false |
showTree |
Whether to show the tree structure in the report | true |
showSummary |
Whether to show the summary information | true |
scanModules |
Automatically scan for exec files in project modules | false |
baseDir |
Base directory for module scanning | ${project.basedir} |
additionalExecFiles |
Additional exec files to include in the report | [] |
weightClassCoverage |
Weight for class coverage in combined score | 0.1 |
weightMethodCoverage |
Weight for method coverage in combined score | 0.1 |
weightBranchCoverage |
Weight for branch coverage in combined score | 0.4 |
weightLineCoverage |
Weight for line coverage in combined score | 0.4 |
ignoreFilesInBuildDirectory |
Ignore autogenerated files in build directory | true |
[INFO] Overall Coverage Summary
[INFO] Package │ Class, % │ Method, % │ Branch, % │ Line, %
[INFO] --------------------------------------------------------------------------------------------------------------------------------------------------------
[INFO] com.example │ 100.00% (3/3) │ 83.33% (5/6) │ 50.00% (2/4) │ 75.00% (15/20)
[INFO] ├─model │ 100.00% (1/1) │ 100.00% (2/2) │ 50.00% (1/2) │ 87.50% (7/8)
[INFO] └─util │ 100.00% (1/1) │ 100.00% (2/2) │ 50.00% (1/2) │ 87.50% (7/8)
[INFO] --------------------------------------------------------------------------------------------------------------------------------------------------------
[INFO] all classes │ 100.00% (3/3) │ 83.33% (5/6) │ 50.00% (2/4) │ 75.00% (15/20)
[INFO] Overall Coverage Summary
[INFO] ------------------------
[INFO] Class coverage : 100.00% (3/3)
[INFO] Method coverage: 83.33% (5/6)
[INFO] Branch coverage: 50.00% (2/4)
[INFO] Line coverage : 75.00% (15/20)
[INFO] Combined coverage: 68.33% (Class 10%, Method 10%, Branch 40%, Line 40%)
[INFO] Overall Coverage Summary
[INFO] Package │ Class, % │ Method, % │ Branch, % │ Line, %
[INFO] --------------------------------------------------------------------------------------------------------------------------------------------------------
[INFO] com.example │ 100.00% (3/3) │ 83.33% (5/6) │ 50.00% (2/4) │ 75.00% (15/20)
[INFO] ├─model │ 100.00% (1/1) │ 100.00% (2/2) │ 50.00% (1/2) │ 87.50% (7/8)
[INFO] │ └─Model.java │ 100.00% (1/1) │ 100.00% (2/2) │ 50.00% (1/2) │ 87.50% (7/8)
[INFO] ├─util │ 100.00% (1/1) │ 100.00% (2/2) │ 50.00% (1/2) │ 87.50% (7/8)
[INFO] │ └─Util.java │ 100.00% (1/1) │ 100.00% (2/2) │ 50.00% (1/2) │ 87.50% (7/8)
[INFO] └─Example.java │ 100.00% (1/1) │ 33.33% (1/2) │ 0.00% (0/0) │ 25.00% (1/4)
[INFO] --------------------------------------------------------------------------------------------------------------------------------------------------------
[INFO] all classes │ 100.00% (3/3) │ 83.33% (5/6) │ 50.00% (2/4) │ 75.00% (15/20)
[INFO] Overall Coverage Summary
[INFO] ------------------------
[INFO] Class coverage : 100.00% (3/3)
[INFO] Method coverage: 83.33% (5/6)
[INFO] Branch coverage: 50.00% (2/4)
[INFO] Line coverage : 75.00% (15/20)
[INFO] Combined coverage: 68.33% (Class 10%, Method 10%, Branch 40%, Line 40%)
The plugin is configured by default to defer reporting until the end.
This will wait with generating the report until the last module in the build.
If your JaCoCo plugin uses a non-default location for the execution data file:
<plugin>
<groupId>io.github.svaningelgem</groupId>
<artifactId>jacoco-console-reporter</artifactId>
<version>1.0.0</version>
<configuration>
<jacocoExecFile>${project.build.directory}/custom-jacoco.exec</jacocoExecFile>
</configuration>
<!-- ... -->
</plugin>
You can configure which parts of the report are displayed:
<plugin>
<groupId>io.github.svaningelgem</groupId>
<artifactId>jacoco-console-reporter</artifactId>
<version>1.0.0</version>
<configuration>
<!-- Show or hide the tree structure -->
<showTree>true</showTree>
<!-- Show or hide individual source files -->
<showFiles>true</showFiles>
<!-- Show or hide the summary information -->
<showSummary>true</showSummary>
</configuration>
<!-- ... -->
</plugin>
You can adjust the weights used to calculate the combined coverage score:
<plugin>
<groupId>io.github.svaningelgem</groupId>
<artifactId>jacoco-console-reporter</artifactId>
<version>1.0.0</version>
<configuration>
<weightClassCoverage>0.2</weightClassCoverage>
<weightMethodCoverage>0.2</weightMethodCoverage>
<weightBranchCoverage>0.3</weightBranchCoverage>
<weightLineCoverage>0.3</weightLineCoverage>
</configuration>
<!-- ... -->
</plugin>
The plugin supports excluding specific files or packages from coverage reports. There are two ways to configure exclusions:
-
Using JaCoCo Exclusions: The plugin automatically respects exclusion patterns defined in your JaCoCo plugin configuration:
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <configuration> <excludes> <exclude>com/example/generated/**/*</exclude> <exclude>**/*Controller.class</exclude> <exclude>com/example/model/*</exclude> </excludes> </configuration> </plugin>
-
Automatically Exclude Build Directory Files: By default, the plugin will ignore files in the build directory, which are typically auto-generated. You can disable this with:
<plugin> <groupId>io.github.svaningelgem</groupId> <artifactId>jacoco-console-reporter</artifactId> <configuration> <ignoreFilesInBuildDirectory>false</ignoreFilesInBuildDirectory> </configuration> </plugin>
The exclusion pattern for JaCoCo is:
*
matches any character except path separators**
matches any directory- File paths use
/
as separator regardless of the operating system - Patterns without the
.class
suffix will automatically match class files
For example:
com/example/model/*
- Excludes all files directly in the model packagecom/example/generated/**/*
- Excludes all files in generated and its subpackages**/*Controller.class
- Excludes all files ending with "Controller.class" in any package
The plugin works by:
- Detecting JaCoCo execution data files (default or custom locations)
- Loading the execution data using JaCoCo's API
- Analyzing compiled classes using the execution data
- Building a hierarchical directory structure representing the package organization
- Calculating coverage metrics (class, method, branch, line) for each node
- Generating a tree-like report to the console
- Computing a weighted combined coverage score
- Applying exclusion patterns to filter out specific files or packages
Contributions are welcome! Feel free to submit issues or pull requests to enhance this plugin.
mvn clean install
mvn test