Skip to content

v4 SPI: ProjectTransformer — functional model transformation at reactor assembly time (afterProjectsRead replacement) #13808

Closed

Description

@gnodet

Summary

AbstractMavenLifecycleParticipant.afterProjectsRead() is the primary hook used by build extensions (Tycho, Quarkus, GraalVM native-build-tools, jgitver, …) to mutate reactor projects after collection but before the topological sort. The Maven v4 API needs a proper SPI replacement.

Proposed SPI in maven-api-spi

@Experimental
@Consumer
@ThreadSafe
public interface ProjectTransformer extends SpiService {
    /**
     * Called after all reactor projects have been read and before the reactor is sorted for execution.
     * Transformers are called in sequence; the model returned by one transformer is passed as input
     * to the next. The final model is written back into the project by the runtime.
     *
     * Implementations may return a modified model built via {@code Model.newBuilder(model)...build()}.
     * Throwing aborts the build.
     *
     * @param session the build session
     * @param project the project (read-only; reflects original state before any transformer ran)
     * @param model   the model as modified by preceding transformers in the chain
     * @return the transformed model; must not be null
     */
    @Nonnull
    Model transformProject(
            @Nonnull Session session,
            @Nonnull Project project,
            @Nonnull Model model) throws MavenException;
}

Why a functional signature instead of ProjectManager.setModel()

The Model → Model signature is composable by design. With a setModel() approach, two transformers calling it independently have last-writer-wins semantics — each silently discards the other's changes. The functional approach forces the runtime to thread the model through all transformers in sequence, making composition explicit and safe.

Execution in the runtime

The runtime chains all ProjectTransformer instances (ordered by priority) for each project:

Model result = project.getModel();
for (ProjectTransformer t : transformers) {
    result = t.transformProject(session, project, result);
}
// write result back into project

Then validates the final model has not modified immutable fields, then proceeds to the second buildGraph() (topological re-sort).

What can and cannot be changed

At step 9 in DefaultMaven.doExecute(), nothing has been resolved remotely yet — no artifacts downloaded, no plugin classloaders loaded, no execution plans built. All of the following are still mutable:

  • ✅ <dependencies> — Tycho use case (P2 → Maven dep injection)
  • ✅ <build> / <plugins> / <pluginManagement> — Quarkus, GraalVM (Surefire/Failsafe arg injection)
  • ✅ <properties> — already covered by PropertyContributor but accessible here too
  • ✅ <dependencyManagement>

The runtime must reject (or warn on) changes to frozen fields after all transformers have run:

  • ❌ groupId / artifactId — reactor identity; changing breaks getProjectMap() and workspace resolution
  • ❌ <parent> — inheritance already assembled
  • ❌ <modules> — project set is fixed; adding/removing projects is not supported at this point
  • ❌ <profiles> — already activated

Why not per-project vs. reactor-scoped

Both a per-project ProjectTransformer and a reactor-scoped variant are needed:

  • Per-project (this interface) — for transformations that are self-contained per project (Quarkus, GraalVM)
  • Reactor-scoped — for transformations that need cross-project visibility (Tycho: P2 dependency resolution across the whole reactor). See companion interface ReactorTransformer.

Real use case coverage

Extension What it mutates Covered by
Tycho <dependencies> (P2 → Maven) ReactorTransformer (needs full reactor)
Quarkus Surefire/Failsafe plugin config ProjectTransformer
GraalVM native-build-tools Surefire/Failsafe plugin config ProjectTransformer
jgitver version (done via ModelProcessor) Already covered; nisse supersedes

Relationship to other SPIs

  • PropertyContributor (exists) — fires at session start, before projects read; properties only
  • ProjectTransformer (this) — fires at step 9; per-project model transformation
  • ReactorTransformer — fires at step 9, same point; needs full reactor list for cross-project reasoning
  • Graph SPI (Define v4 API for project dependency graph and migrate graph builder #13463) — fires at step 6/10; reactor graph structure and topological ordering

Related

Activity

  1. added
    enhancement
    on Nov 3, 2026
  2. changed the title [-]v4 SPI: ReactorTransformer — mutate reactor projects before graph sort (afterProjectsRead replacement)[/-] [+]v4 SPI: ProjectTransformer — functional model transformation at reactor assembly time (afterProjectsRead replacement)[/+] on Nov 3, 2026
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