|
1 |
| -# Jacoco Console Reporter Maven Plugin |
| 1 | +# JaCoCo Console Reporter Maven Plugin |
2 | 2 |
|
3 |
| -A custom Maven plugin that generates a textual tree-like coverage report from JaCoCo's `jacoco.exec` file, displaying coverage metrics (Class %, Method %, Branch %, Line %) for packages, source files, and the entire project. |
| 3 | +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. |
4 | 4 |
|
5 | 5 | ## Features
|
6 |
| -- Reads coverage data from `jacoco.exec` |
| 6 | +- Reads coverage data from `jacoco.exec` files |
7 | 7 | - Analyzes class files from the project's build output directory
|
8 | 8 | - Outputs a hierarchical console-based report with coverage metrics
|
9 |
| -- Tree-like package structure visualization |
| 9 | +- Tree-like package structure visualization with collapsible paths |
10 | 10 | - Instant visibility of coverage metrics during build
|
| 11 | +- Multi-module project support with option to defer reporting until the end |
| 12 | +- Automatic scanning for `jacoco.exec` files across modules |
| 13 | +- Support for custom JaCoCo execution file patterns |
11 | 14 |
|
12 | 15 | ## Prerequisites
|
13 | 16 | - Maven 3.x
|
@@ -45,20 +48,105 @@ Ensure the JaCoCo plugin has executed beforehand to generate jacoco.exec.
|
45 | 48 |
|
46 | 49 | ## Configuration
|
47 | 50 |
|
48 |
| -* `jacocoExecFile`: Path to `jacoco.exec` (default: `${project.build.directory}/jacoco.exec`) |
49 |
| -* `classesDirectory`: Directory containing compiled classes (default: `${project.build.outputDirectory}`) |
| 51 | +| Parameter | Description | Default Value | |
| 52 | +|-----------------------|-----------------------------------------------------------|------------------------------------------| |
| 53 | +| `jacocoExecFile` | Path to the JaCoCo execution data file | `${project.build.directory}/jacoco.exec` | |
| 54 | +| `classesDirectory` | Directory containing compiled classes | `${project.build.outputDirectory}` | |
| 55 | +| `deferReporting` | Defer reporting until the end (for multi-module projects) | `false` | |
| 56 | +| `showFiles` | Whether to show individual source files in the report | `true` | |
| 57 | +| `scanModules` | Automatically scan for exec files in project modules | `false` | |
| 58 | +| `baseDir` | Base directory for module scanning | `${project.basedir}` | |
| 59 | +| `additionalExecFiles` | Additional exec files to include in the report | `[]` | |
50 | 60 |
|
51 | 61 | ## Example Output
|
52 | 62 | ```text
|
53 | 63 | [INFO] Overall Coverage Summary
|
54 | 64 | [INFO] Package | Class, % | Method, % | Branch, % | Line, %
|
55 | 65 | [INFO] --------------------------------------------------------------------------------------------------------------------------------------------------------
|
56 |
| -[INFO] com.example | 50.00% (1/2) | 33.33% (2/6) | 25.00% (1/4) | 40.00% (4/10) |
57 |
| -[INFO] ├─ Calculator.java | 50.00% (1/2) | 50.00% (1/2) | 0.00% (0/0) | 50.00% (1/2) |
58 |
| -[INFO] └─ AdvancedCalculator.java | 100.00% (1/1) | 25.00% (1/4) | 25.00% (1/4) | 37.50% (3/8) |
| 66 | +[INFO] com.example | 100.00% (3/3) | 83.33% (5/6) | 50.00% (2/4) | 75.00% (15/20) |
| 67 | +[INFO] ├─model | 100.00% (1/1) | 100.00% (2/2) | 50.00% (1/2) | 87.50% (7/8) |
| 68 | +[INFO] │ └─Model.java | 100.00% (1/1) | 100.00% (2/2) | 50.00% (1/2) | 87.50% (7/8) |
| 69 | +[INFO] ├─util | 100.00% (1/1) | 100.00% (2/2) | 50.00% (1/2) | 87.50% (7/8) |
| 70 | +[INFO] │ └─Util.java | 100.00% (1/1) | 100.00% (2/2) | 50.00% (1/2) | 87.50% (7/8) |
| 71 | +[INFO] └─Example.java | 100.00% (1/1) | 33.33% (1/2) | 0.00% (0/0) | 25.00% (1/4) |
59 | 72 | [INFO] --------------------------------------------------------------------------------------------------------------------------------------------------------
|
60 |
| -[INFO] all classes | 75.00% (2/3) | 33.33% (2/6) | 25.00% (1/4) | 40.00% (4/10) |
| 73 | +[INFO] all classes | 100.00% (3/3) | 83.33% (5/6) | 50.00% (2/4) | 75.00% (15/20) |
61 | 74 | ```
|
62 | 75 |
|
| 76 | +## Advanced Usage |
| 77 | + |
| 78 | +### Multi-Module Projects |
| 79 | + |
| 80 | +For multi-module projects, you can configure the plugin to aggregate coverage across modules. All configuration values are the defaults so they don't have to be added, but are shown here for completeness’s sake: |
| 81 | + |
| 82 | +```xml |
| 83 | +<plugin> |
| 84 | + <groupId>io.github.svaningelgem</groupId> |
| 85 | + <artifactId>jacoco-console-reporter</artifactId> |
| 86 | + <version>1.0.0</version> |
| 87 | + <configuration> |
| 88 | + <jacocoExecFile>${project.build.directory}/jacoco.exec</jacocoExecFile> |
| 89 | + <classesDirectory>${project.build.outputDirectory}</classesDirectory> |
| 90 | + <deferReporting>true</deferReporting> |
| 91 | + <showFiles>true</showFiles> |
| 92 | + <additionalExecFiles /> |
| 93 | + <scanModules>false</scanModules> |
| 94 | + <baseDir>${project.basedir}</baseDir> |
| 95 | + </configuration> |
| 96 | + <executions> |
| 97 | + <execution> |
| 98 | + <goals> |
| 99 | + <goal>report</goal> |
| 100 | + </goals> |
| 101 | + <phase>verify</phase> |
| 102 | + </execution> |
| 103 | + </executions> |
| 104 | +</plugin> |
| 105 | +``` |
| 106 | + |
| 107 | +This configuration will: |
| 108 | +- Defer the reporting until the last module in the build |
| 109 | +- Automatically scan for JaCoCo execution files in all modules |
| 110 | + |
| 111 | +### Custom JaCoCo File Locations |
| 112 | + |
| 113 | +If your JaCoCo plugin uses a non-default location for the execution data file: |
| 114 | + |
| 115 | +```xml |
| 116 | +<plugin> |
| 117 | + <groupId>io.github.svaningelgem</groupId> |
| 118 | + <artifactId>jacoco-console-reporter</artifactId> |
| 119 | + <version>1.0.0</version> |
| 120 | + <configuration> |
| 121 | + <jacocoExecFile>${project.build.directory}/custom-jacoco.exec</jacocoExecFile> |
| 122 | + </configuration> |
| 123 | + <!-- ... --> |
| 124 | +</plugin> |
| 125 | +``` |
| 126 | + |
| 127 | +## Implementation Details |
| 128 | + |
| 129 | +The plugin works by: |
| 130 | + |
| 131 | +1. Detecting JaCoCo execution data files (default or custom locations) |
| 132 | +2. Loading the execution data using JaCoCo's API |
| 133 | +3. Analyzing compiled classes using the execution data |
| 134 | +4. Building a hierarchical directory structure representing the package organization |
| 135 | +5. Calculating coverage metrics (class, method, branch, line) for each node |
| 136 | +6. Generating a tree-like report to the console |
| 137 | + |
63 | 138 | ## Contributing
|
64 |
| -Contributions are welcome! Feel free to submit issues or pull requests to enhance this plugin. |
| 139 | + |
| 140 | +Contributions are welcome! Feel free to submit issues or pull requests to enhance this plugin. |
| 141 | + |
| 142 | +### Building from Source |
| 143 | + |
| 144 | +```bash |
| 145 | +mvn clean install |
| 146 | +``` |
| 147 | + |
| 148 | +### Running Tests |
| 149 | + |
| 150 | +```bash |
| 151 | +mvn test |
| 152 | +``` |
0 commit comments