This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-4.0.x by this push:
     new d7fa0576ee [backport maven-4.0.x] #14119: fix: concurrent builder 
skips install/deploy after test failure (#14114) (#14138)
d7fa0576ee is described below

commit d7fa0576eede1cb1346cc81c173f46ee8fc7966c
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Nov 27 00:42:07 2026 +0100

    [backport maven-4.0.x] #14119: fix: concurrent builder skips install/deploy 
after test failure (#14114) (#14138)
---
 .../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 f2a011049b..b9ecb34886 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
@@ -419,8 +419,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 a6b2fac890..3d19689db5 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;
     }
 

Reply via email to