Skip to content

Fix #12571: Build Report Foundation — structured report, console modes, warning control - #12572

Draft
gnodet wants to merge 2 commits into
masterfrom
feature/12571-build-report
Draft

Fix #12571: Build Report Foundation — structured report, console modes, warning control#12572
gnodet wants to merge 2 commits into
masterfrom
feature/12571-build-report

Conversation

@gnodet

@gnodet gnodet commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the build output overhaul proposed in #12571: a structured BuildReport data model with JSON persistence, a DiagnosticCollector for deduplicated warning summaries, four --console modes (plain, rich, machine, verbose), a --warning-mode CLI flag, automatic Log.warn() interception for Maven 3 plugin warnings, and per-key diagnostic suppression.

What's included

Structured Build Report

  • BuildReportModuleReportMojoReport data model in maven-api-core with id() and findModule()/findMojo() lookup methods
  • Per-mojo and per-module log capture using structured LogEvent
  • FailureReport with timestamp, exception type, and stack trace
  • BuildReportCollector (EventSpy, @Named @Singleton) — captures lifecycle events
  • BuildReportJsonWriter — hand-written JSON serializer (no library dependency)
  • Persists target/build-report.json at session end
  • API lives in org.apache.maven.api.build.report sub-package

DiagnosticCollector + Warning Summary

  • Diagnostic / DiagnosticCollector / DiagnosticSummary API
  • DefaultDiagnosticCollector — thread-safe (ConcurrentHashMap + LongAdder), dedup by key, capped at 1000
  • Deduplicated warning summary printed at end of build with counts, suggestions, doc URLs
  • Diagnostics written to build-report.json

Console Modes (--console)

Flag Behavior
--console=auto (default) CI → plain; TTY → rich; otherwise → verbose
--console=plain One line per module, no ANSI — auto-selected in CI
--console=rich JLine status bar with live reactor progress, parallel-build aware
--console=verbose Full mojo-level output (Maven 4.0 default)
--console=machine JSON lines — one typed event per line, designed for tools and LLM agents

Plain mode: compact footer, no ANSI control sequences.
Rich mode: live Status bar showing active modules, [n/total] progress, elapsed time, download progress. Falls back gracefully on dumb terminals.
Machine mode: one JSON object per line with typed "event" field and ISO-8601 timestamps. Events: build.started/finished, module.started/succeeded/failed/skipped, mojo.*, fork.*, transfer.*.

Warning Mode, Log Interception, Diagnostic Suppression

Flag Behavior
--warning-mode=summary (default) Collect and show deduplicated summary at end
--warning-mode=all Show inline + summary
--warning-mode=none Suppress diagnostic summary
--warning-mode=fail Show summary + fail build if warnings exist
  • Log.warn() interception — auto-feeds Maven 3 plugin WARN-level output into DiagnosticCollector via synthetic dedup keys (auto:<LoggerSuffix>:<hexHash>), with file-coordinate stripping so the same warning from different files deduplicates
  • -Dmaven.diagnostic.suppress=<key> — suppress diagnostics by exact key or prefix wildcard (auto:*)

What's NOT included (separate work)

  • Core plugin migration (maven-compiler-plugin, maven-enforcer-plugin, maven-surefire-plugin, maven-dependency-plugin reporting structured Diagnostic objects)
  • mvn build-report:show plugin

Tests

91 unit tests across 10 test classes covering report assembly, JSON serialization, diagnostic dedup/suppression/concurrency, all console modes, and all warning modes. Integration tests that assert on verbose log output explicitly set --console=verbose to work correctly under CI auto-detection.

@gnodet gnodet changed the title Fix #12571: Add structured build report (Phase 0) Fix #12571: Build output overhaul — structured report, console modes, warning control Jul 29, 2026
@gnodet gnodet changed the title Fix #12571: Build output overhaul — structured report, console modes, warning control Fix #12571: Build Report Foundation — structured report, console modes, warning control Jul 29, 2026
@gnodet
gnodet force-pushed the feature/12571-build-report branch 3 times, most recently from 0d88607 to bda1ea0 Compare July 29, 2026 07:56
…s, warning control

Adds a structured BuildReport data model (BuildReport → ModuleReport →
MojoReport) with JSON persistence to target/build-report.json, a
DiagnosticCollector for deduplicated warning summaries, four --console
modes (plain, rich, machine, verbose), a --warning-mode CLI flag,
automatic Log.warn() interception for Maven 3 plugins, and per-key
diagnostic suppression via -Dmaven.diagnostic.suppress.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet
gnodet force-pushed the feature/12571-build-report branch from bda1ea0 to 2f33c5f Compare July 29, 2026 08:42
Replace the raw String parameter in BuildEventListener.projectLogMessage()
with a structured LogEvent that carries level, logger name, clean message,
formatted output, and stack trace. This enables console renderers to filter
by log level — rich mode now suppresses INFO during the build and only shows
WARN/ERROR.

Key changes:
- Add formattedMessage() to LogEvent API for pre-formatted console output
- Replace Consumer<String> logSink with structured LogSink interface in
  MavenSimpleLogger, carrying level/loggerName/cleanMessage/formatted/throwable
- Add context-aware write() overload in MavenBaseLogger to pass level context
- ProjectBuildLogAppender creates LogEvent objects from the structured sink
- Rich mode filters INFO/DEBUG/TRACE in projectLogMessage()
- Machine mode emits level and logger fields in JSON output
- Verbose/plain modes use formattedMessage() for backward-compatible output

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