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 468bda953a [Backport maven-4.0.x] #14156: fix: concurrent builder runs 
verify phase before package (#14151) (#14158)
468bda953a is described below

commit 468bda953ac7f216a9f1549e40210f51e2804fff
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Nov 28 00:36:52 2026 +0100

    [Backport maven-4.0.x] #14156: fix: concurrent builder runs verify phase 
before package (#14151) (#14158)
---
 .../internal/impl/DefaultLifecycleRegistry.java    |  1 +
 .../internal/concurrent/BuildPlanCreatorTest.java  | 41 ++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git 
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
 
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
index 2117f6d91e..6181b701d9 100644
--- 
a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
+++ 
b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java
@@ -497,6 +497,7 @@ public Collection<Phase> phases() {
                             phase(
                                     VERIFY,
                                     after(VALIDATE),
+                                    after(BUILD),
                                     phase(
                                             UNIT_TEST,
                                             phase(TEST_SOURCES),
diff --git 
a/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanCreatorTest.java
 
b/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanCreatorTest.java
index 492a1cdeea..f7646b3711 100644
--- 
a/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanCreatorTest.java
+++ 
b/impl/maven-core/src/test/java/org/apache/maven/lifecycle/internal/concurrent/BuildPlanCreatorTest.java
@@ -661,4 +661,45 @@ protected void mojo(Consumer<String> writer, MojoExecution 
mojoExecution) {}
         });
     }
      */
+
+    /**
+     * Regression test for <a 
href="https://github.com/apache/maven/issues/14151";>#14151</a>:
+     * with the concurrent builder, goals bound to the {@code verify} phase 
(e.g.
+     * {@code failsafe:verify}, {@code jacoco:check}) must not run before 
compilation,
+     * tests and packaging complete.
+     *
+     * <p>Root cause: the {@code VERIFY} container phase only declared {@code 
after(VALIDATE)},
+     * so its {@code before:verify} build step had no ordering edge to {@code 
after:build}.
+     * The fix adds {@code after(BUILD)} to the {@code VERIFY} phase 
definition, ensuring
+     * {@code before:verify executeAfter after:build} in the DAG.</p>
+     */
+    @Test
+    void testVerifyPhaseWaitsForBuild() {
+        MavenProject project = new MavenProject();
+        project.setCollectedProjects(List.of());
+        Map<MavenProject, List<MavenProject>> projects = 
Collections.singletonMap(project, Collections.emptyList());
+
+        BuildPlan plan = calculateLifecycleMappings(projects, "verify");
+
+        // before:verify must transitively depend on after:build (and 
therefore after:package).
+        // We verify this by checking that after:build is reachable in the 
predecessor graph
+        // of before:verify — i.e. before:verify cannot be scheduled before 
build completes.
+        BuildStep beforeVerify = plan.requiredStep(project, "before:verify");
+        boolean afterBuildIsPrerequisite = beforeVerify
+                .allPredecessors()
+                .anyMatch(step -> step.project == project && 
"after:build".equals(step.name));
+
+        assertTrue(
+                afterBuildIsPrerequisite,
+                "before:verify must transitively depend on after:build so that 
mojos bound to "
+                        + "'verify' (e.g. failsafe:verify, jacoco:check) 
cannot run before "
+                        + "compilation, test and packaging complete (#14151)");
+
+        // Symmetrically, after:package (a child of build) must also be a 
transitive prerequisite.
+        boolean afterPackageIsPrerequisite = beforeVerify
+                .allPredecessors()
+                .anyMatch(step -> step.project == project && 
"after:package".equals(step.name));
+
+        assertTrue(afterPackageIsPrerequisite, "before:verify must 
transitively depend on after:package (#14151)");
+    }
 }

Reply via email to