feat(maven-plugin): add depclean:report goal for the Maven Site (#478) - #546
feat(maven-plugin): add depclean:report goal for the Maven Site (#478)#546patbaumgartner wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The snapshot reuse fingerprint currently includes test output even when ignoreTests=true, unnecessarily invalidating reuse and undermining the PR’s “avoid analyzing twice” behavior for that configuration.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds a new Maven Site reporting goal (depclean:report) to the depclean-maven-plugin, generating an HTML report integrated into Maven Site’s “Project Reports” section and reusing prior DepClean analysis results via a snapshot file to avoid duplicate analysis runs.
Changes:
- Introduces
depclean:reportbuilt on the Maven Reporting API / Doxia 2, rendering a DepClean report page via a Doxia sink renderer. - Adds snapshot + input fingerprinting (
target/depclean-analysis.json) sodepclean:depcleananddepclean:reportcan share analysis results safely. - Adds unit + integration tests and updates docs/CI/scripts to cover the new goal and its usage.
File summaries
| File | Description |
|---|---|
| scripts/set-version.sh | Updates README version syncing to handle both :depclean and :report CLI examples. |
| README.md | Documents the new Maven Site report goal, usage, and site plugin version requirement. |
| depclean-maven-plugin/src/main/java/se/kth/depclean/DepCleanReportMojo.java | Implements the report goal as a Maven report, including snapshot reuse + fallback analysis. |
| depclean-maven-plugin/src/main/java/se/kth/depclean/report/DepCleanReportRenderer.java | Renders the report content using Doxia sinks (tables, sections, anchors, details). |
| depclean-maven-plugin/src/main/java/se/kth/depclean/report/AnalysisSnapshot.java | Defines the serializable snapshot model handed off between goals. |
| depclean-maven-plugin/src/main/java/se/kth/depclean/report/AnalysisSnapshotFile.java | Reads/writes the JSON snapshot and validates reuse conditions. |
| depclean-maven-plugin/src/main/java/se/kth/depclean/report/AnalysisInputs.java | Computes an inputs fingerprint from POM + compiled class files to detect staleness. |
| depclean-maven-plugin/src/main/java/se/kth/depclean/DepCleanMojo.java | Persists a snapshot after depclean:depclean so depclean:report can reuse it. |
| depclean-maven-plugin/pom.xml | Adds Maven reporting/Doxia dependencies required for the report implementation/tests. |
| depclean-maven-plugin/src/test/java/se/kth/depclean/report/DepCleanReportRendererTest.java | Unit-tests renderer output structure/content via an XHTML sink. |
| depclean-maven-plugin/src/test/java/se/kth/depclean/report/AnalysisSnapshotFileTest.java | Unit-tests snapshot JSON roundtrip and reuse gating. |
| depclean-maven-plugin/src/test/java/se/kth/depclean/report/AnalysisInputsTest.java | Unit-tests fingerprint stability and change detection semantics. |
| depclean-maven-plugin/src/test/java/se/kth/depclean/DepCleanReportMojoIT.java | Integration-tests report generation via mvn site and snapshot reuse/recompute scenarios. |
| depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanReportMojoIT/report_via_site/pom.xml | IT fixture for site generation and “Project Reports” listing verification. |
| depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanReportMojoIT/report_via_site/src/main/java/Greeter.java | IT fixture source to ensure one dependency is used and another remains unused. |
| depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanReportMojoIT/report_reuses_analysis/pom.xml | IT fixture for package + depclean:report reuse behavior. |
| depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanReportMojoIT/report_reuses_analysis/src/main/java/Greeter.java | IT fixture source for reuse test case. |
| depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanReportMojoIT/report_recomputes_when_stale/pom.xml | IT fixture for standalone report recomputation when no prior snapshot exists. |
| depclean-maven-plugin/src/test/resources-its/se/kth/depclean/DepCleanReportMojoIT/report_recomputes_when_stale/src/main/java/Greeter.java | IT fixture source for stale/recompute test case. |
| .github/workflows/build.yml | Extends runtime smoke to also run :report and validate it reuses analysis + renders output. |
Review details
- Files reviewed: 20/20 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…RT-KTH#478) Add a Maven Reporting API mojo that renders the DepClean analysis as target/site/depclean.html under "Project Reports": a per-category summary, a table per category (used/unused x direct/transitive/inherited, plus ignored) with coordinates, scope and size, and the classes the project uses from each used dependency. The goal forks test-compile so bare `mvn site` works. depclean:depclean now writes target/depclean-analysis.json; the report reuses it when the settings match and neither the POM nor the compiled classes changed, so `mvn verify site` analyses the project only once. The report is read-only: it never writes pom-debloated.xml nor fails the build. Built on maven-reporting-impl 4.0.0 (Doxia 2), which requires maven-site-plugin >= 3.20.0; verified on Maven 3.9.16 and 4.0.0-rc-6.
…ME version in sync The runtime-smoke job is the only place the plugin runs on JDK 8, so it now also invokes depclean:report and checks that the analysis is reused and the Doxia 2 stack renders target/reports/depclean.html. set-version.sh learns the ':report' command line in the README so a release bump does not leave it stale.
…imes On windows-latest the test-compile lifecycle forked by depclean:report recompiles the (unchanged) sources, so the class files end up newer than target/depclean-analysis.json and the report re-ran the analysis instead of reusing it, failing DepCleanReportMojoIT.report_reuses_analysis. Store a SHA-256 fingerprint of the POM and the .class bytes in the snapshot and reuse it only while that fingerprint still matches. Bytes are stable across a no-op recompile, while real source or POM changes still invalidate the snapshot.
…s reads With ignoreTests=true the analysis never looks at target/test-classes, yet both depclean:depclean and depclean:report hashed it into the snapshot fingerprint. Any test recompilation therefore invalidated the stored snapshot and forced a redundant re-analysis for exactly the configuration that asked to leave tests out. AnalysisInputs.classDirectories() now yields the main output directory and adds the test output directory only when tests are analysed; both mojos use it, so writer and reader agree on the inputs.
05d153e to
a04c828
Compare
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #546 +/- ##
============================================
+ Coverage 53.76% 57.46% +3.70%
Complexity 337 337
============================================
Files 52 57 +5
Lines 2814 3120 +306
Branches 361 395 +34
============================================
+ Hits 1513 1793 +280
- Misses 1203 1218 +15
- Partials 98 109 +11
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|



Closes #478.
What
Adds a
depclean:reportgoal built on the Maven Reporting API (maven-reporting-impl4.0.0 / Doxia 2) that renders the DepClean analysis astarget/site/depclean.html, listed in the site's Project Reports section.The page contains:
ignoreTests,ignoreScopes,ignoreDependencies) and whether the result was reused or freshly computed;used / totalclasses;How
DepCleanReportMojo extends AbstractMavenReport,@Execute(phase = TEST_COMPILE), so a baremvn siteworks without a prior build. It is read-only: never writespom-debloated.xml, never appliesfailIfUnused*; skips cleanly forskipDepCleanandpompackaging.depclean:depcleannow always writes a small gson snapshot totarget/depclean-analysis.json. The report reuses it only when the settings match and the file is newer thanpom.xmland every compiled class undertarget/classes/target/test-classes; otherwise it analyses itself and writes the snapshot. A file handoff was chosen overMavenProjectcontext values becausemaven-site-pluginloads report plugins in their own ClassRealm, so in-memoryProjectDependencyAnalysisinstances would not be type-compatible across goals.DepCleanReportRenderer extends AbstractMavenReportRenderer(Doxia sink, no HTML templates).ignoreDependencies/ignoreScopes/ignoreTests/skipDepCleanare shared with thedepcleangoal under the same property names.Compatibility
enforceBytecodeVersionrule, andruntime-smokenow also runsdepclean:reporton JDK 8/17/21/25 (verified locally with a real JDK 8 runtime).maven-site-plugin>= 3.20.0 (Doxia 2). Maven 3.9 still defaults to 3.12.1, so users must pin a recent version — documented in the README. Maven 4 (default site plugin 4.0.0-M16) works out of the box; the site IT passes on both 3.9.16 and 4.0.0-rc-6.Usage
mvn site->target/site/depclean.html; standalonemvn se.kth.castor:depclean-maven-plugin:<v>:report->target/reports/depclean.html.Tests
AnalysisSnapshotFileTest(round trip; freshness: missing / newer pom / newer class / different settings / corrupt file),DepCleanReportRendererTest(renders throughXhtml5Sink, asserts structure, anchors,-for a null scope, empty analysis).DepCleanReportMojoIT):report_via_site(mvn site, page listed inproject-reports.html, nopom-debloated.xml),report_reuses_analysis(package depclean:reportreuses the snapshot, banner printed once),report_recomputes_when_stale(standalone report analyses itself)../mvnw -ntp clean verify --errorsgreen;scripts/set-version.sh --checkgreen (the script now also tracks the:reportcommand line in the README).Supersedes #540, which GitHub auto-closed when the fork was re-created (same commits, same branch).