Skip to content

Migrate Project Builder to v4 API (invert delegation) #13461

Open

Description

@gnodet

Part of #13460 — Migrate Maven internals from v3 to v4 API

Context

Currently the v4 ProjectBuilder service (api/maven-api-services/.../ProjectBuilder.java) is implemented by a thin wrapper in maven-core/.../internal/impl/DefaultProjectBuilder (~232 lines) that delegates back to the v3 DefaultProjectBuilder (maven-core/.../project/DefaultProjectBuilder, ~1420 lines). The delegation arrow is backwards.

The v3 project builder already delegates to the v4 ModelBuilder internally (which was migrated in a previous effort), so the hardest sub-problem (model building) is solved.

Goal

Invert the delegation so the real project-building logic lives in impl/maven-impl using v4 types natively, and the v3 project builder in maven-core (or compat/) becomes a thin wrapper.

Key files

  • v4 API: api/maven-api-services/.../services/ProjectBuilder.java
  • v4 wrapper (currently delegates to v3): impl/maven-core/.../internal/impl/DefaultProjectBuilder.java
  • v3 implementation (real logic): impl/maven-core/.../project/DefaultProjectBuilder.java
  • v4 Project: impl/maven-core/.../internal/impl/DefaultProject.java (currently wraps MavenProject)
  • v3 MavenProject: impl/maven-core/.../project/MavenProject.java

Mutability Design

This phase introduces the immutable snapshots + mutable reference holder pattern (see #13460 for full design):

  • Project (v4) is truly immutable — a consistent snapshot of all project state
  • MutableProject (internal) holds a reference to the current Project snapshot. It is the stable identity passed through the build pipeline.
  • ProjectManager mutates by reading the current snapshot, creating a new Project via with*()/builder, and swapping the reference in MutableProject
  • MavenProject (v3 compat) wraps MutableProject: reads delegate to the current snapshot, writes go through ProjectManager

v4 API additions needed

Project needs build-time state fields (resolved dependencies, attached artifacts, source roots) and either with*() methods or an internal builder to produce updated snapshots.

Approach

  1. Add build-time state to the Project interface (resolved dependencies, attached artifacts, source roots, properties)
  2. Create MutableProject as an internal reference holder in impl/maven-impl
  3. Create DefaultProjectBuilder in impl/maven-impl implementing o.a.m.api.services.ProjectBuilder — works with v4 types natively, produces MutableProject instances
  4. Update DefaultProjectManager to work with MutableProject (snapshot swap) instead of reaching into MavenProject
  5. The v3 DefaultProjectBuilder becomes a thin wrapper that delegates to the v4 builder and wraps MutableProject into MavenProject
  6. DefaultProject holds v4 types natively instead of wrapping MavenProject
  7. Related classes to migrate: ProjectBuildingHelper, ProjectDependenciesResolver, collection strategies

Compatibility

MavenProject stays available for plugins — it becomes a wrapper around MutableProject:

  • mavenProject.getGroupId() → reads from mutableProject.getProject().getGroupId()
  • mavenProject.addAttachedArtifact(a) → goes through ProjectManager, which swaps the snapshot

Dependencies

  • None (model builder is already v4-native)

Complexity

Medium-high. ~1400 lines of logic to restructure, plus the MutableProject infrastructure and Project API additions.

Claude Code on behalf of Guillaume Nodet

Activity

  1. added
    enhancement
    on Oct 13, 2026
  2. ayush-builds-stuff commented on Nov 24, 2026

    @ayush-builds-stuff

    Hi @gnodet, I’d like to work on this issue.

    Before starting, I’d like to confirm the intended scope:

    1. Should the work target master?
    2. The DefaultProject inversion is also listed as Quick Win 2 in Quick wins: migrate event loggers and DefaultProject to v4 API #13467. Should that be handled under Quick wins: migrate event loggers and DefaultProject to v4 API #13467 first, or as the first phase of Migrate Project Builder to v4 API (invert delegation) #13461?
    3. Since the complete builder migration is large, would you prefer incremental PRs? I’m considering starting with the project-state foundation (Project snapshots, the internal MutableProject holder, and compatibility tests for MavenProject) before moving the builder itself.
    4. Is there already a preferred design for mapping an immutable Project snapshot back to its MutableProject holder, or should I propose that design in the first PR?

    Once these points are confirmed, I can prepare a focused first change.

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