Repository navigation
Add ProjectTransformer SPI for functional model transformation at reactor assembly time - #13647
Conversation
Introduce structured lifecycle callbacks for reactor discovery, per-project execution, and session shutdown. Expose project dependency mutation through ProjectManager and bridge callbacks through both standard and concurrent lifecycle execution.
gnodet-bot
left a comment
There was a problem hiding this comment.
Several issues with the dispatcher's fault-isolation contract and one uncaught exception path in the concurrent executor.
Issue 1 — call() does not isolate participant failures (high)
LifecycleParticipantDispatcher.call() iterates participants sequentially with no per-participant try/catch inside the loop. If participant A throws LifecycleParticipantException, the loop exits immediately and all subsequent participants are silently skipped. For afterProjectExecution and afterSessionEnd — which are notification/cleanup callbacks — this means one misbehaving extension can prevent all others from running their teardown. The legacy AbstractMavenLifecycleParticipant dispatcher collects per-participant exceptions rather than failing fast; the new dispatcher should do the same.
Issue 2 — afterProjectExecution on success path in BuildPlanExecutor is not guarded (high)
The failure path at line 572 wraps afterProjectExecution in try/catch (LifecycleExecutionException e) { failure.addSuppressed(e); }. The success path at line 583 does not. When executeStep() throws, the exception is caught by the outer catch (Throwable e) Runnable at line ~435 and stored as step.exception. At TEARDOWN, a non-null step.exception triggers the failure branch — so a LifecycleParticipantException from a participant's afterProjectExecution callback turns a successful project build into a reported failure.
Issue 3 — Missing @since on ProjectManager.setDependencies() (low)
The method is new in this PR; the class-level @since 4.0.0 does not cover new methods. Needs @since 4.1.0 in the method Javadoc to match the @since on LifecycleParticipant and ProjectExecutionEvent.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Invoke all lifecycle participants even when callbacks fail and aggregate subsequent callback failures as suppressed exceptions. Treat after-project callback failures as fatal build failures, document the new ProjectManager API version, and add focused regression coverage.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier review — all 3 previously flagged issues have been addressed in this commit. One new issue introduced by the revision.
Previously raised:
- Issue 1 (dispatcher fault isolation) — ✅ addressed:
call()now collects per-participant exceptions and suppresses subsequent ones. - Issue 2 (
afterProjectExecutionsuccess path guard) — ✅ addressed inBuildPlanExecutorwith separate try/catch wrapping the dispatcher call. - Issue 3 (missing
@since 4.1.0onsetDependencies()) — ✅ addressed.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Keep project execution success and failure listener notifications mutually exclusive when an after-project lifecycle participant fails. Document the public exception constructors, make lifecycle test recording safe for empty plans, and cover the listener sequence with a regression test.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier reviews — all 9 previously flagged issues have been addressed in this revision.
Previously raised:
- Issue 1 (dispatcher fault isolation) — ✅ addressed:
call()collects per-participant exceptions withaddSuppressed. - Issue 2 (
afterProjectExecutionsuccess path guard inBuildPlanExecutor) — ✅ addressed:try/catchwithhandleBuildError+return. - Issue 3 (missing
@since 4.1.0onsetDependencies()) — ✅ addressed. - Issues 4–6 (missing Javadoc on
LifecycleParticipantExceptionconstructors) — ✅ addressed. - Issues 7–8 (
executionPlan().get(0)IndexOutOfBoundsException in test) — ✅ addressed:isEmpty()guard inRecordingLifecycleParticipant.goal(). - Issue 9 (inconsistent
ProjectExecutionListenerevent sequence) — ✅ addressed:projectSuccessReportedflag ensuresafterProjectExecutionFailureis not called when success was already reported.
One low-severity nit on test code duplication (non-blocking).
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Extract the map-backed SessionData implementation shared by the lifecycle participant dispatcher and executor tests into a single test utility.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier reviews — the previous nit (test utility duplication of MapBackedSessionData) has been addressed in commit c4e45ff9, which extracted it into a shared class imported by all three test classes. ✅
The merge commit (550e3ff3) is a clean merge of origin/master with no new production code introduced. No new issues found.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet
left a comment
There was a problem hiding this comment.
Thanks for the PR — this addresses a real gap. After reviewing the implementation and discussing the design, I think the scope needs to be refocused and the core mutation API redesigned before this lands.
What this PR gets right
afterProjectsReadis the critical hook — it's the one method fromAbstractMavenLifecycleParticipantthat has no v4 equivalent and is actively used by major extensions (Tycho, Quarkus, GraalVM native-build-tools).- Firing at step 9 in
DefaultMaven.doExecute()(before the secondbuildGraph()re-sort) is exactly right — at this point nothing has been resolved remotely, so all project metadata is still safely mutable. - The SPI belongs in
maven-api-spias aSpiService— correct, since core extensions need startup discovery before a fullSessionexists.
1. Drop beforeProjectExecution, afterProjectExecution, afterSessionEnd
These belong in a ProjectExecutionListener extends Listener in maven-api-core (tracked in #13807), following the existing ExecutionListener/RepositoryListener pattern. Keeping them here:
- Puts
ProjectExecutionEventin the wrong module (maven-api-spiinstead ofmaven-api-core) - Duplicates listener dispatch infrastructure
afterSessionEndis already covered byExecutionListener.sessionEnded()
Narrow this PR to the afterProjectsRead replacement only.
2. Replace setDependencies() with a functional ProjectTransformer SPI
ProjectManager.setDependencies() is too narrow. Looking at the actual extension use cases:
- Tycho — replaces
<dependencies>wholesale with P2-resolved Maven coords - Quarkus — injects JVM flags into Surefire/Failsafe plugin configuration
- GraalVM native-build-tools — injects agent args into Surefire/Failsafe plugin configuration
setDependencies() covers only Tycho. Quarkus and GraalVM need plugin configuration mutation — a separate setter, with the same last-writer-wins problem if two extensions both call it.
The right model is a functional transformer that threads the Model through all registered transformers in sequence (tracked in #13808):
@Consumer
public interface ProjectTransformer extends SpiService {
@Nonnull Model transformProject(
@Nonnull Session session,
@Nonnull Project project,
@Nonnull Model model) throws MavenException;
}The runtime chains all transformers ordered by priority, then writes the final model back into the project. This:
- Covers all mutation use cases through the immutable
Model.BuilderAPI without accumulating individual setters - Composes safely — each transformer sees the output of the previous, no silent overwrite
- Lets the runtime validate the final model hasn't touched frozen fields (
groupId/artifactId/<parent>/<modules>/<profiles>)
For cross-project use cases (Tycho needs the full reactor list to resolve P2 deps), a companion ReactorTransformer that receives List<Project> fires at the same lifecycle point.
3. Rename
LifecycleParticipant implies general lifecycle participation which this PR doesn't fully deliver. With the scope narrowed to afterProjectsRead, the name should be ProjectTransformer (per-project, functional) and/or ReactorTransformer (cross-project).
4. @Named does not belong on the interface
@Named is a DI annotation for implementations. Remove it from the SPI interface.
Suggested path forward
@nAmed on a SPI interface has no functional effect: DiIndexProcessor is not configured on maven-api-spi, so no DI index is generated from it. Furthermore, getDeclaredAnnotations() does not traverse implemented interfaces (Java does not inherit interface annotations to implementing classes), so @nAmed on the interface would not cause implementations to be discovered automatically. The annotation is therefore purely decorative and misleading. Implementations that need to be discovered must annotate their own concrete class with @nAmed.
|
@copilot resolve the merge conflicts on this branch. |
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on the latest commit (merge conflict resolution via Copilot, 2026-11-07).
The merge conflicts have been resolved and the code rebased successfully. However, the structural design issues raised in @gnodet's 2026-11-03 review remain fully open:
Still pending:
-
Scope is still too broad —
LifecycleParticipantretains all 4 methods (afterProjectsRead,beforeProjectExecution,afterProjectExecution,afterSessionEnd). The request was to narrow this PR toafterProjectsReadonly, moving the execution callbacks to aProjectExecutionListenerinmaven-api-core(#13807). -
ProjectManager.setDependencies()not replaced — the method is still present. The request was to replace it with a functionalProjectTransformerSPI that threads theModelthrough all extensions in sequence (#13808). -
Naming unchanged —
LifecycleParticipant/ProjectExecutionEventnames unchanged. With the scope narrowed toafterProjectsRead, the natural names would beProjectTransformer/ReactorTransformer. -
ProjectExecutionEventmodule placement — still inmaven-api-spi. Since execution callbacks are to move tomaven-api-core(#13807),ProjectExecutionEventshould follow.
What this commit did address:
@Namedannotation removed from theLifecycleParticipantinterface ✅
No new issues were introduced by the conflict resolution. The implementation quality remains solid — the dispatcher fault-isolation, ClassLoader context-switching, and concurrent-engine integration are all well done. The remaining blockers are design-level and require the scope/naming/API changes discussed before this can land.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Address review feedback by removing execution callbacks (beforeProjectExecution, afterProjectExecution, afterSessionEnd) from the LifecycleParticipant SPI. These belong in a separate ProjectExecutionListener in maven-api-core (apache#13807). - Remove ProjectExecutionEvent from maven-api-spi (follows the execution callbacks to their future home) - Remove all dispatch infrastructure for the removed methods from LifecycleParticipantDispatcher, DefaultMaven, LifecycleModuleBuilder, and BuildPlanExecutor - Keep the ProjectExecutionListener fix that prevents both success and failure callbacks from firing for the same project - Update all affected tests Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
gnodet-bot
left a comment
There was a problem hiding this comment.
Two findings from the verifier pass, plus a note on pending design items from @gnodet's earlier review.
Fault isolation — RuntimeException from a buggy extension will escape the inner catch (LifecycleParticipantException) block, skip remaining participants in the loop, and propagate up unchecked. Consider catching RuntimeException in the per-participant loop and wrapping it in a LifecycleParticipantException, or at minimum documenting this behaviour explicitly.
Javadoc no-op note — the afterProjectsRead default implementation is an empty body, but the Javadoc doesn't say so. Implementors should know upfront there's nothing to delegate through.
Pending design items from @gnodet's review — two open items from the previous round appear unaddressed:
setDependencies→ should this be part of aProjectTransformerSPI rather than onLifecycleParticipant?- Naming:
LifecycleParticipantvsProjectTransformer— the original naming discussion is still open.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
- Catch RuntimeException in per-participant loop to maintain fault isolation — a buggy extension no longer skips remaining participants - Add Javadoc note that afterProjectsRead default implementation does nothing - Remove unused mockito imports from BuildPlanExecutorTest (spotless) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier reviews — 3 of the 5 open items have been addressed.
Addressed in this push:
- ✅ Fault isolation —
LifecycleParticipantDispatcher.call()now catches bothLifecycleParticipantException | RuntimeExceptionper participant, accumulates all failures withaddSuppressed, and re-throws after all participants run. Thefinallyblock correctly restores the original ClassLoader regardless of participant errors. - ✅ Javadoc no-op —
afterProjectsReadnow statesThe default implementation does nothing. - ✅ Scope narrowed — execution callbacks (
beforeProjectExecution,afterProjectExecution,afterSessionEnd) removed fromLifecycleParticipant; the concurrent executor now correctly dispatches them to the existingProjectExecutionListenerSPI.
Still open (from @gnodet's Nov 3 review):
1. ProjectManager.setDependencies() vs functional ProjectTransformer SPI
The setDependencies method is still present on ProjectManager. @gnodet's original CHANGES_REQUESTED asked to replace this with a functional ProjectTransformer that threads the Model through all extensions in sequence (tracked in #13808). The imperative setDependencies API allows one extension to silently overwrite another’s dependency list when multiple extensions register — the functional approach composes safely. This design question is unresolved.
2. Naming: LifecycleParticipant vs ProjectTransformer
The name LifecycleParticipant was flagged by @gnodet with the note that once scope is narrowed to afterProjectsRead, the natural name is ProjectTransformer (per-project, functional) or ReactorTransformer (cross-project). The name is still LifecycleParticipant.
No new issues were introduced by these commits. The dispatcher implementation is correct. Waiting on the two design decisions before this can land.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
… SPI (apache#13808) Replace the void-callback LifecycleParticipant with a functional ProjectTransformer that takes a Model and returns a transformed Model. The runtime chains all transformers in sequence per reactor project and writes the final model back. - Add ProjectTransformer SPI in maven-api-spi (Model → Model) - Remove LifecycleParticipant and LifecycleParticipantException - Remove ProjectManager.setDependencies() — transformers return modified models via Model.withDependencies() instead - Add ProjectTransformerDispatcher that iterates reactor projects, chains transformers with classloader isolation, and writes back - Update tests to use the functional transformer pattern Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
gnodet-bot
left a comment
There was a problem hiding this comment.
Review Summary
This is a new ProjectTransformer SPI and dispatcher that enables v4 API extensions to transform reactor project models. The implementation is clean and well-tested.
Three minor points:
-
@ThreadSafeinconsistency —ProjectTransformeris the only SPI interface annotated with@ThreadSafe. Other SPI interfaces (ModelParser,DependencyResolver,LanguageProvider, etc.) do not carry this annotation. This creates an implicit contract that users might miss or question for other SPIs. Consider either annotating all SPIs that have thread-safety guarantees, or adding a note in the Javadoc explaining why@ThreadSafeis required here specifically. -
afterProjectExecutionFailureordering differs between execution paths — InBuildPlanExecutor,afterProjectExecutionFailureis called beforehandleBuildError. InLifecycleModuleBuilder, it is called afterhandleBuildError. This asymmetry is worth documenting if it is intentional; implementors ofProjectExecutionListenermay observe different reactor state whenafterProjectExecutionFailurefires depending on which executor ran the build. -
Spurious blank line in
DefaultProjectManager— a double blank line was introduced between the constructor closing brace and the@Nonnullannotation.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
- Remove @threadsafe from ProjectTransformer — no other SPI uses it - Fix afterProjectExecutionFailure/handleBuildError ordering in BuildPlanExecutor to match LifecycleModuleBuilder (handleBuildError first, then listener notification) - Remove spurious blank line in DefaultProjectManager Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Resolve conflict in BuildPlanExecutor: keep both executionPlan() helper (from this branch) and bindProjectMojos() (from master). Also improve ProjectTransformer Javadoc with allowed/frozen fields. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The runtime now rejects changes to groupId, artifactId, parent, mixins, modules, and profiles — modifying these after model inheritance and profile activation would break reactor identity and module structure. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Move validation inside the transformer loop so the error message names the exact transformer class that made the illegal change. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on my earlier reviews — all 3 open threads from the last round are now addressed.
Addressed in this push:
- ✅
@ThreadSafeannotation — removed fromProjectTransformer. Consistent with all other SPI interfaces. - ✅
afterProjectExecutionFailureordering asymmetry — fixed. BothBuildPlanExecutorandLifecycleModuleBuildernow callafterProjectExecutionFailureafterhandleBuildError. - ✅ Spurious blank line in
DefaultProjectManager— single blank line confirmed at line 75. Clean.
One new issue in LifecycleModuleBuilder:
The successReported flag is set after afterProjectExecutionSuccess() returns, not before. If afterProjectExecutionSuccess() itself throws (listener bug), execution falls into the catch block with successReported = false, causing afterProjectExecutionFailure to fire for a build that actually succeeded. Implementors of ProjectExecutionListener would observe both callbacks for the same project.
Move the flag set before the call (see inline comment).
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Following up on the earlier review posted moments ago — three additional issues found in the new validateFrozenFields logic and its Javadoc.
1. validateFrozenFields omits <subprojects> — ModelBase has two separate fields: getModules() (deprecated since 4.0.0) and getSubprojects() (the Maven 4.1.0 replacement). The check only tests getModules(), so a transformer using model.withSubprojects(...) silently bypasses the frozen-field restriction. Add the same guard for getSubprojects().
2. Javadoc timing claim is wrong — The Javadoc says validation runs "after all transformers have run" but the code calls validateFrozenFields() inside the per-transformer loop. It validates after each transformer, not after all. Correct the description (and this is actually the better design — it names the offending transformer precisely in the error message).
3. No test for rejection paths — ProjectTransformerDispatcherTest has two tests (chaining and RuntimeException wrapping). Neither verifies that modifying a frozen field throws MavenExecutionException. Add at least one test for the rejection path (e.g. a transformer that returns model.withArtifactId("changed")).
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Report all illegally modified fields at once rather than failing on the first one. Message format: "The ProjectTransformer com.example.Foo must not change groupId/artifactId, <parent>, <modules> of g:a:v" Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
gnodet-bot
left a comment
There was a problem hiding this comment.
Four issues found in this PR — all confirmed against the diff.
1. validateFrozenFields omits getSubprojects()
The validateFrozenFields method checks groupId/artifactId, <parent>, <mixins>, <modules>, and <profiles> — but not <subprojects>. A ProjectTransformer that calls model.withSubprojects(...) silently bypasses the frozen-field guard. The frozen-field list in the ProjectTransformer Javadoc also omits <subprojects>. Both need to be fixed together.
2. Javadoc timing claim is wrong
The Javadoc on ProjectTransformer says the runtime rejects changes "after all transformers have run" — but the actual code calls validateFrozenFields inside the per-transformer loop (after each transformer, not after all of them). The semantics differ: the current code validates per step, while the doc implies a final-state check. Update the Javadoc to match the code.
3. successReported = true is set after the listener
afterProjectExecutionSuccess(...) is called on line 115–116, then successReported = true is set on line 117. If the listener throws, control transfers to the catch block where successReported is still false, causing afterProjectExecutionFailure to fire for a build that actually succeeded. The flag should be set before the listener call, or the listener call should be outside the try/catch (or guarded separately).
4. No test for the frozen-field rejection path
ProjectTransformerDispatcherTest has two tests: transformer chaining, and RuntimeException wrapping. Neither test verifies that mutating a frozen field (e.g. changing groupId or <modules>) actually throws MavenExecutionException. Add a test that passes a transformer which modifies groupId and asserts the exception message.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
- Set successReported before afterProjectExecutionSuccess() call so a listener exception doesn't also trigger afterProjectExecutionFailure - Add <subprojects> to frozen-field validation and Javadoc - Fix Javadoc: "after each transformer runs" not "after all" - Add test for frozen-field rejection path Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This comment has been minimized.
This comment has been minimized.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review: the four previously-flagged issues are all addressed — good progress. One new compilation error introduced in this push: assertTrue is called in ProjectTransformerDispatcherTest without a static import.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review: the compilation error from the previous review (missing static import for assertTrue) is now fixed. All prior findings across this review series are addressed.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Re-review: the latest commit (6237e1b) applies Spotless formatting only — no semantic changes. Line-break reflowing in string concatenations and test method calls in ProjectTransformerDispatcher.java and ProjectTransformerDispatcherTest.java.
All prior findings remain resolved. LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
gnodet-bot
left a comment
There was a problem hiding this comment.
Verifier pass on 2426b0bf: removes the shared MapBackedSessionData test utility from impl/maven-core/src/test/.../internal/impl/. Confirmed no remaining imports or references to the deleted class — DefaultTempFileServiceTest has its own inner class of the same name and is unaffected. All 24 review threads remain resolved.
LGTM.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Summary
Introduces a
ProjectTransformerSPI inmaven-api-spithat replaces the v3AbstractMavenLifecycleParticipant.afterProjectsRead()hook with a functional, composable design.ProjectTransformer— takes aModeland returns a transformedModel. The runtime chains all transformers in sequence per reactor project and writes the final model back before the topological re-sort.groupId/artifactId,<parent>,<mixins>,<modules>/<subprojects>, and<profiles>after each transformer, with error messages that name the offending class.ProjectManager.setDependencies()— replaced by the functionalmodel.withDependencies(...)pattern, which composes safely (no last-writer-wins).LifecycleParticipant,LifecycleParticipantException, andProjectExecutionEvent— execution callbacks (beforeProjectExecution,afterProjectExecution,afterSessionEnd) are out of scope and tracked in v4 API: Add ProjectExecutionListener and ProjectExecutionEvent to maven-api-core #13807.Closes #13514, implements #13808.
Motivation
Extensions like Tycho, Quarkus, and GraalVM native-build-tools need to mutate reactor project models after collection but before execution. The v3
AbstractMavenLifecycleParticipant.afterProjectsRead()works but exposes v3 types. The initial v4LifecycleParticipantused a void callback +ProjectManager.setDependencies(), which has last-writer-wins semantics when multiple extensions mutate the same project.The functional
Model → Modelsignature makes composition explicit: each transformer sees the output of the previous one.Test plan
MavenLifecycleParticipantTest— v3 lifecycle listeners still work; v4ProjectTransformerinjects reactor dependencies and affects ordering; recording transformer verifies dispatchProjectTransformerDispatcherTest— transformer chaining writes model back;RuntimeExceptionwrapped inMavenExecutionException; frozen-field violation rejected with descriptive messageSpotless formatting passes
CI (
mvn verify)I hereby declare this contribution to be licensed under the Apache License Version 2.0, January 2004