Skip to content

Report structured BuilderProblems from compiler diagnostics - #1101

Draft
gnodet wants to merge 2 commits into
masterfrom
feature/12644-diagnostic-reporter
Draft

Report structured BuilderProblems from compiler diagnostics#1101
gnodet wants to merge 2 commits into
masterfrom
feature/12644-diagnostic-reporter

Conversation

@gnodet

@gnodet gnodet commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Maps javax.tools.Diagnostic to BuilderProblem and reports via the new DiagnosticReporter service from Maven 4.1.0, so compiler warnings and errors appear with structured keys, source locations, and severity in the build report and mvnlog --diagnostics output.

Related: apache/maven#12644 — follow-up to apache/maven#12572 (Build Report Foundation).

Changes

  • AbstractCompilerMojo: Add @Inject DiagnosticReporter diagnosticReporter
  • DiagnosticLogger: Accept DiagnosticReporter in constructor; for each javax.tools.Diagnostic, create a BuilderProblem with:
    • key("compiler:<code>:<source>:<line>") — per-location dedup key, e.g. compiler:compiler.warn.unchecked:src/main/java/Foo.java:42
    • severity mapped from Diagnostic.Kind (ERROR→ERROR, WARNING→WARNING, etc.)
    • source, lineNumber, columnNumber from the diagnostic
  • ToolExecutor: Pass diagnosticReporter through to DiagnosticLogger
  • pom.xml: Bump mavenVersion to 4.1.0-SNAPSHOT for DiagnosticReporter API

Design decisions

  • Per-location dedup key: Each diagnostic uses "compiler:<code>:<source>:<line>" as the key, so each unique file+line gets its own entry in the build report. This preserves per-file detail — 10 unchecked warnings across 10 files produce 10 separate entries, not one collapsed entry with count=10.
  • Suppression: Users can suppress compiler diagnostics via -Dmaven.diagnostic.suppress=compiler:* (all) or compiler:compiler.warn.unchecked (specific prefix).
  • No behavior change: Existing logging behavior is unchanged — DiagnosticReporter is additive.

Test changes

  • Updated test imports for maven-testing package relocation (4.0.0-rc-4 → 4.1.0-SNAPSHOT)
  • Added no-op DiagnosticReporter provider in test DI configuration

Test plan

  • mvn test — 16 tests pass, 0 failures
  • End-to-end verified: built Maven 4.1.0-SNAPSHOT distribution + this plugin against a test project producing 12 compiler warnings across 2 files → 10 per-location structured entries in build report JSON
  • CI — expected to fail until Maven 4.1.0-SNAPSHOT is published (needs DiagnosticReporter API from apache/maven#12572)

Dependencies

This PR requires Maven core 4.1.0-SNAPSHOT which includes:

  • DiagnosticReporter service (apache/maven#12572)
  • BuilderProblem.builder() with key(), suggestion(), documentationUrl() fields

Map javax.tools.Diagnostic to BuilderProblem and report via the new
DiagnosticReporter service, so compiler warnings and errors appear
with structured keys, source locations, and severity in the build
report and mvnlog --diagnostics output.

- Add @Inject DiagnosticReporter to AbstractCompilerMojo
- Pass DiagnosticReporter to DiagnosticLogger constructor
- Map each Diagnostic to BuilderProblem with key "compiler:<code>",
  severity from Diagnostic.Kind, and source file/line/column
- Use per-type key for dedup (e.g. "compiler:compiler.warn.unchecked"
  counts all unchecked warnings as one summary entry)
- Bump mavenVersion to 4.1.0-SNAPSHOT for DiagnosticReporter API
- Update test imports for maven-testing package relocation
- Add no-op DiagnosticReporter provider in test configuration

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

gnodet commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

CI status: ⚠️ CI fails as expected — the build requires maven-api-core:4.1.0-SNAPSHOT (for DiagnosticReporter), which is not yet published. The CI matrix tests against 4.0.0-rc-4.

This PR is ready for review but will only pass CI once Maven core #12572 is merged and a SNAPSHOT is deployed.

Tests pass locally against a locally-installed 4.1.0-SNAPSHOT (16/16 pass, 0 checkstyle violations).

Change the BuilderProblem key from per-type (compiler:<code>) to
per-location (compiler:<code>:<source>:<line>) so each unique
file+line keeps its own entry in the build report. Warnings of the
same type in different files are no longer collapsed into a single
entry.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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