Repository navigation
Description
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 byPropertyContributorbut 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 breaksgetProjectMap()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 onlyProjectTransformer(this) — fires at step 9; per-project model transformationReactorTransformer— 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
- v4 SPI: Lifecycle participation (afterProjectsRead, per-project callbacks, session end) #13514 — original lifecycle participation issue (PR Add ProjectTransformer SPI for functional model transformation at reactor assembly time #13647 implements this)
- v4 API: Add ProjectExecutionListener and ProjectExecutionEvent to maven-api-core #13807 — ProjectExecutionListener for before/after project execution callbacks
- Allow Listener implementations to be auto-discovered as SPI services #13805 — Listener auto-discovery as SpiService
- Define v4 API for project dependency graph and migrate graph builder #13463 — reactor graph SPI
- v4 API/SPI gaps for build extensions — analysis from Tycho #13499 — Tycho analysis of v4 SPI gaps
Activity
[-]v4 SPI: ReactorTransformer — mutate reactor projects before graph sort (afterProjectsRead replacement)[/-][+]v4 SPI: ProjectTransformer — functional model transformation at reactor assembly time (afterProjectsRead replacement)[/+]feat: replace LifecycleParticipant with functional ProjectTransformer…
feat: introduce ProjectTransformer SPI for functional model transform…