Skip to content

Define v4 Maven execution service API for embedded use #13472

Open

Description

@gnodet

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:

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 in Session, 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

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

  1. added
    enhancement
    on Oct 13, 2026
  2. gnodet commented on Oct 14, 2026

    @gnodet
    ContributorAuthor

    Cross-referencing #13499 (updated with m2e analysis) — the v4 execution service API should cover two m2e-specific requirements:

    1. 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, calling setupMojoExecution() and ensureDependenciesAreResolved() per mojo. A proper API like session.executePartialPlan(project, filteredMojoExecutions) would let Maven handle phase-boundary dependency resolution and ordering correctly.

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

  3. wozhenbang2004 commented on Nov 24, 2026

    @wozhenbang2004
    Contributor

    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 BuildReportCollector test against #14077 at e5969627. 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions