Skip to content

Add a spotless:report goal for the Maven site - #3175

Open
patpatpat123 wants to merge 3 commits into
diffplug:mainfrom
patpatpat123:maven-site-report
Open

patpatpat123 wants to merge 3 commits into
diffplug:mainfrom
patpatpat123:maven-site-report

Conversation

@patpatpat123

Copy link
Copy Markdown

Hi! 👋

The problem

A lot of Maven projects publish a site with mvn site, and most code quality tools show up there under Project Reports: Checkstyle, PMD, SpotBugs, JaCoCo, Surefire. Spotless doesn't, and adding it to <reporting> doesn't help: maven-site-plugin only renders goals that implement MavenReport, so it skips all three Spotless goals (Skipping non-MavenReport in the debug log). Today the only way to see what Spotless would change is to run spotless:check and read the console, where the diff is capped at about 50 lines.

What this adds

A new spotless:report goal. List the plugin under <reporting>, and mvn site gets a Spotless page:

<reporting>
  <plugins>
    <plugin>
      <groupId>com.diffplug.spotless</groupId>
      <artifactId>spotless-maven-plugin</artifactId>
    </plugin>
  </plugins>
</reporting>
  • A summary per format: how many files are clean, need formatting or have lint problems, with a small overview bar.
  • The files with problems, each linking to its own page with a colored diff of what spotless:apply would change. Tabs and trailing whitespace are highlighted, since they're invisible otherwise.
  • A table of lint problems: line, step, code and message.

mvn spotless:report writes the same pages to target/site without building the whole site. The report never changes a file and never fails the build because of violations.

How it works

  • SpotlessReportMojo extends AbstractSpotlessMojo, so it supports every format and step, and looks at exactly the files spotless:check would (ratchetFrom, spotlessFiles and <lintSuppressions> apply).
  • One jar for both generations of the site plugin. maven-site-plugin 3.12.x (Doxia 1, still Maven 3.9's default) and 3.20+ (Doxia 2) both call MavenMultiPageReport.generate(Sink, SinkFactory, Locale), whose signature is the same in reporting API 3.1.1 and 4.0.0, and the renderer only calls Sink methods that both Doxia 1.11 and 2.0 have (all 47 checked). New runtime dependencies: maven-reporting-api and doxia-sink-api, about 20 KB, no Doxia renderer.
  • No duplicated configuration. mvn site configures report goals only from <reporting> and <pluginManagement>, so the goal copies the plugin-level <build> configuration onto itself; anything set in <reporting> wins.
  • Leaves the up-to-date index alone. Two small hooks in AbstractSpotlessMojo plus UpToDateChecker.ignoringIndex(); check and apply behave exactly as before.

Testing

  • Unit tests for the diff and the rendering.
  • Integration tests: standalone run, both skip properties, the index staying byte-for-byte the same, and mvn site with maven-site-plugin 3.12.1 and 3.21.0, including <reporting> overriding <build>.
  • I also tried it on a real project with maven-site-plugin 3.12.1 and 3.22.0.

I couldn't run the full Gradle build locally, so CI will be the first full run of the integration tests and spotlessCheck. I'll fix whatever comes up, and put this PR's number in the changelog right after opening it.

Thanks for Spotless, and for taking a look!

🤖 Generated with Claude Code

patpatpat123 and others added 3 commits November 8, 2026 16:06
spotless-maven-plugin had no report goal, so maven-site-plugin skipped it
and a project's site could not show Spotless results. The new
spotless:report goal implements MavenMultiPageReport: mvn site gets a
Spotless page with a summary per format, the files that need formatting,
each with a colored diff of what spotless:apply would change, and the
lint problems. mvn spotless:report writes the same pages on its own.

It works with maven-site-plugin 3.12.x (Doxia 1) and 3.20+ (Doxia 2),
reuses the plugin-level <build> configuration, and never touches the
up-to-date index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant