Repository navigation
Description
Part of #13460 — Migrate Maven internals from v3 to v4 API
Context
Today, embedding Maven programmatically requires using the v3 entry point:
Maven.execute(MavenExecutionRequest) → MavenExecutionResult
MavenExecutionRequest is a massive mutable bean (~80 getters/setters) mixing CLI concerns, session config, and execution parameters. The v4 API needs a clean equivalent so Maven can be used embedded without going through the CLI layer (InvokerRequest / Parser).
The v4 API already has building blocks:
BuildReport,BuildEnvironment(PR Build report: structured JSON report with per-mojo log capture #12695) — structured execution output and invocation contextInvokerRequest/Parser/Options(api/maven-api-cli) — CLI-specific parsingSession— holds configuration, projects, settings, repositories
What's missing is a service + request/result for programmatic execution.
Proposed Design
Follow the established v4 pattern (Service.method(Request) → Result):
// api/maven-api-services
@Experimental
interface Maven {
MavenExecutionResult execute(MavenExecutionRequest request);
}
@Immutable
interface MavenExecutionRequest {
Session session();
List<String> goals();
List<String> selectedProjects(); // -pl equivalent
String resumeFrom(); // -rf equivalent
List<String> activeProfileIds();
// ... clean, focused set of execution parameters
static Builder builder() { ... }
}
@Immutable
interface MavenExecutionResult {
BuildReport report();
boolean isSuccessful();
List<FailureReport> failures();
}Two entry points, same service
CLI: InvokerRequest → Parser → builds MavenExecutionRequest → Maven.execute()
Embedder: builds MavenExecutionRequest directly → Maven.execute()
Key differences from v3 MavenExecutionRequest
- Immutable with a builder — same pattern as
ModelBuilderRequest,ProjectBuilderRequest, etc. - No mixed concerns — CLI parsing stays in
InvokerRequest/Parser, session config stays inSession, execution request is just "what to build and how" - Result wraps
BuildReport— leveraging the structured report from Build report: structured JSON report with per-mojo log capture #12695 instead of a loose bag of exceptions
Compatibility
The v3 Maven.execute(MavenExecutionRequest) stays for embedders that depend on it. Its implementation delegates to the v4 service internally, adapting request/result types.
Dependencies
- Benefits from Build report: structured JSON report with per-mojo log capture #12695 (BuildReport / BuildEnvironment) for the result type
- Should be designed alongside Session inversion (Migrate Session to v4 API (invert MavenSession / Session) #13462)
- Will be consumed by Migrate DefaultMaven orchestrator and CLI to v4 API #13466 (orchestrator/CLI migration)
Complexity
Medium. This is primarily API design + a thin implementation layer. The hard part is deciding what belongs on the execution request vs on the session.
Claude Code on behalf of Guillaume Nodet
Activity
gnodet commentedon Oct 14, 2026
Cross-referencing #13499 (updated with m2e analysis) — the v4 execution service API should cover two m2e-specific requirements:
Partial/filtered lifecycle execution: m2e computes the full lifecycle plan, filters it (via lifecycle mapping metadata), then executes surviving mojos one-by-one because there's no API for "run this filtered subset of the plan." It manually reimplements
MojoExecutor's inner loop, callingsetupMojoExecution()andensureDependenciesAreResolved()per mojo. A proper API likesession.executePartialPlan(project, filteredMojoExecutions)would let Maven handle phase-boundary dependency resolution and ordering correctly.Multi-session management: m2e manages concurrent Maven sessions on different threads (one per project refresh). The embedding API needs to support session creation and concurrent execution without casting to
DefaultMaven.Claude Code on behalf of Guillaume Nodet
wozhenbang2004 commentedon Nov 24, 2026
m2e still calls
DefaultMaven.newRepositorySession()when it starts a refresh. Would you prefer a public API for opening and closing an embedded session in #13462, or as a first step here?I tried the overlapping refresh case in a
BuildReportCollectortest against #14077 ate5969627. With two sessions and separate output directories, starting A, starting B, ending A, then ending B produced a report only for A. Ending A before starting B produced both reports. That seems worth covering in an embedder test so each caller gets its own result.