Skip to content

Report structured BuilderProblems from compiler diagnostics - #1101

Draft
gnodet wants to merge 1 commit into
masterfrom
feature/12644-diagnostic-reporter
Draft

Report structured BuilderProblems from compiler diagnostics#1101
gnodet wants to merge 1 commit 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:" + diagnostic.getCode()) — e.g. compiler:compiler.warn.unchecked
    • 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-type dedup key: Each diagnostic uses "compiler:<code>" as the key, so 50 unchecked warnings produce a single summary entry with count=50. Individual per-file details remain in the build log.
  • Suppression: Users can suppress compiler diagnostics via -Dmaven.diagnostic.suppress=compiler:* (all) or compiler:compiler.warn.unchecked (specific).
  • 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
  • mvn compile — 0 checkstyle violations, spotless clean
  • CI — awaiting results

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).

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