This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push:
new 1b88ba5710 fix: concurrent builder skips install/deploy after test
failure (#14114) (#14119)
1b88ba5710 is described below
commit 1b88ba571059756a35bbe42bbd2146e8815ee61a
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Nov 26 15:41:40 2026 +0100
fix: concurrent builder skips install/deploy after test failure (#14114)
(#14119)
After a build step (e.g. test) fails, its matching after:* cleanup step
runs for cleanup and is marked SKIPPED (not FAILED). The check that
decides whether a later after:* step should run normally or for cleanup
only looked for FAILED predecessors — it missed SKIPPED predecessors.
As a result, after:unit-test, after:verify, install and deploy all ran
normally after a test failure, as if nothing had gone wrong.
The fix extends the anyPredecessorFailed check to include SKIPPED
predecessors. A SKIPPED after:* step signals that an upstream failure
occurred, so any later after:* step that sees it should itself run for
cleanup only (and be marked SKIPPED), not execute normally.
Fixes #14114
---
.../internal/concurrent/BuildPlanExecutor.java | 9 ++-
.../internal/concurrent/BuildPlanExecutorTest.java | 82 +++++++++++++++++++++-
2 files changed, 87 insertions(+), 4 deletions(-)
diff --git
a/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java
b/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java
index dd7371a56c..0461cb11a0 100644
---
a/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java
+++
b/impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutor.java
@@ -534,8 +534,13 @@ private void processStep(BuildStep step) {
})
.orElse(false);
- // Check if any predecessor failed - if so, we'll run the step
but mark it as SKIPPED
- boolean anyPredecessorFailed =
step.predecessors.stream().anyMatch(s -> s.status.get() == FAILED);
+ // Check if any predecessor failed or was itself skipped due
to a failure. An after:*
+ // cleanup step that ran after its own predecessor failed ends
up with status SKIPPED
+ // (not FAILED), so checking FAILED alone is not sufficient:
the failure signal would
+ // be lost and later after:* steps (e.g. after:verify, deploy)
would run normally
+ // even though a nested step (e.g. test) failed.
+ boolean anyPredecessorFailed =
+ step.predecessors.stream().anyMatch(s ->
s.status.get() == FAILED || s.status.get() == SKIPPED);
// If any predecessor failed, we'll use a special status
transition: CREATED -> SKIPPED
// This ensures the step runs for cleanup but is marked as
skipped in the end
diff --git
a/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java
b/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java
index cd8c067683..5705e254e4 100644
---
a/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java
+++
b/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanExecutorTest.java
@@ -49,6 +49,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -363,6 +364,69 @@ void errorIsStillFatalWhenASecondFailureJoinsIt() throws
Exception {
+ session.getResult().getExceptions());
}
+ /**
+ * When a build step (e.g. {@code test}) fails, the matching {@code
after:test} step is run for
+ * cleanup and ends up with status {@code SKIPPED}. Steps that come after
it in the lifecycle
+ * (e.g. {@code after:unit-test}, {@code after:verify}, {@code install},
{@code deploy}) must
+ * also be skipped: they must not run as if the build had succeeded.
+ *
+ * <p>This is the scenario reported in
+ * <a href="https://github.com/apache/maven/issues/14114">#14114</a>: with
the concurrent builder,
+ * {@code install} and {@code deploy} ran even when {@code test} failed,
because the {@code after:*}
+ * cleanup chain converted a {@code FAILED} predecessor into a {@code
SKIPPED} predecessor, and the
+ * subsequent {@code shouldExecute} check only guarded against {@code
FAILED}, not {@code SKIPPED}.
+ */
+ @Test
+ void afterStepSkippedStatusPropagatesAcrossNestedPhases() throws Exception
{
+ MavenProject project = newProject();
+ MavenSession session = newSession(project);
+
+ ReactorContext reactorContext = newReactorContext(session);
+ try (BuildPlanExecutor.BuildContext context =
newExecutor((BeforeProjectExecution) event -> {})
+ .new BuildContext(session, reactorContext,
List.of(newTaskSegment("deploy")))) {
+
+ BuildStep testStep = context.plan
+ .step(project, "test")
+ .orElseThrow(() -> new IllegalStateException("no test step
in the deploy plan"));
+ testStep.exception = new LifecycleExecutionException("test
failure");
+ testStep.status.set(BuildStep.FAILED);
+
+ context.execute();
+
+ // after:test ran for cleanup and must be SKIPPED (not EXECUTED)
+ int afterTestStatus = context.plan
+ .step(project, Lifecycle.AFTER + "test")
+ .map(s -> s.status.get())
+ .orElse(-1);
+ assertEquals(
+ BuildStep.SKIPPED, afterTestStatus, "after:test must be
SKIPPED (ran for cleanup) when test fails");
+
+ // install must NOT have executed
+ int installStatus = context.plan
+ .step(project, "install")
+ .map(s -> s.status.get())
+ .orElse(-1);
+ assertNotEquals(
+ BuildStep.EXECUTED,
+ installStatus,
+ "install must not execute when a predecessor step (test)
has failed");
+
+ // deploy must NOT have executed
+ int deployStatus = context.plan
+ .step(project, "deploy")
+ .map(s -> s.status.get())
+ .orElse(-1);
+ assertNotEquals(
+ BuildStep.EXECUTED,
+ deployStatus,
+ "deploy must not execute when a predecessor step (test)
has failed");
+ }
+
+ assertTrue(
+ session.getResult().getBuildSummary(project) instanceof
org.apache.maven.execution.BuildFailure,
+ "the project must be recorded as a failure when test fails");
+ }
+
private ReactorContext execute(MavenSession session, MavenProject project,
BeforeProjectExecution listener)
throws Exception {
ReactorContext reactorContext = newReactorContext(session);
@@ -381,9 +445,19 @@ private ReactorContext execute(
BeforeProjectExecution listener,
Consumer<BuildPlan> planCustomizer)
throws Exception {
+ return execute(session, project, listener, planCustomizer, "validate");
+ }
+
+ private ReactorContext execute(
+ MavenSession session,
+ MavenProject project,
+ BeforeProjectExecution listener,
+ Consumer<BuildPlan> planCustomizer,
+ String phase)
+ throws Exception {
ReactorContext reactorContext = newReactorContext(session);
try (BuildPlanExecutor.BuildContext context =
- newExecutor(listener).new BuildContext(session,
reactorContext, List.of(newTaskSegment()))) {
+ newExecutor(listener).new BuildContext(session,
reactorContext, List.of(newTaskSegment(phase)))) {
planCustomizer.accept(context.plan);
context.execute();
}
@@ -398,8 +472,12 @@ private ReactorContext newReactorContext(MavenSession
session) {
}
private TaskSegment newTaskSegment() {
+ return newTaskSegment("validate");
+ }
+
+ private TaskSegment newTaskSegment(String phase) {
TaskSegment taskSegment = new TaskSegment(false);
- taskSegment.getTasks().add(new LifecycleTask("validate"));
+ taskSegment.getTasks().add(new LifecycleTask(phase));
return taskSegment;
}