diff --git a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/Lifecycles.java b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/Lifecycles.java index d7ddeeba3d3f..4d20267fc121 100644 --- a/impl/maven-core/src/main/java/org/apache/maven/internal/impl/Lifecycles.java +++ b/impl/maven-core/src/main/java/org/apache/maven/internal/impl/Lifecycles.java @@ -74,6 +74,7 @@ static Plugin plugin(String coords, String phase) { .version(c[2]) .executions(Collections.singletonList(PluginExecution.newBuilder() .id("default-" + c[3]) + .priority(-1) .phase(phase) .goals(Collections.singletonList(c[3])) .location("", DefaultLifecycleRegistry.DEFAULT_LIFECYCLE_INPUT_LOCATION) diff --git a/impl/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/impl/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java index 09f1027e993e..a338aa820757 100644 --- a/impl/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java +++ b/impl/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -313,6 +313,24 @@ MavenExecutionPlan calculateExecutionPlan(MavenSession session, String... tasks) session, session.getCurrentProject(), mergedSegment.getTasks()); } + @Test + void testCleanLifecycleBindingRunsBeforePomExecution() throws Exception { + File pom = getProject("project-with-clean-phase-execution"); + MavenSession session = createMavenSession(pom); + assertEquals( + "project-with-clean-phase-execution", + session.getCurrentProject().getArtifactId()); + List executionPlan = getExecutions(calculateExecutionPlan(session, "clean")); + assertEquals(2, executionPlan.size()); + assertListEquals( + List.of("clean:clean", "it:it"), + executionPlan.stream() + .map(e -> e.getMojoDescriptor().getFullGoalName()) + .toList()); + assertEquals("default-clean", executionPlan.get(0).getExecutionId()); + assertEquals("user-clean-execution", executionPlan.get(1).getExecutionId()); + } + @Test void testInvalidGoalName() throws Exception { File pom = getProject("project-basic"); diff --git a/impl/maven-core/src/test/projects/lifecycle-executor/project-with-clean-phase-execution/pom.xml b/impl/maven-core/src/test/projects/lifecycle-executor/project-with-clean-phase-execution/pom.xml new file mode 100644 index 000000000000..4ee3ccd5ab21 --- /dev/null +++ b/impl/maven-core/src/test/projects/lifecycle-executor/project-with-clean-phase-execution/pom.xml @@ -0,0 +1,92 @@ + + + + + + 4.0.0 + + org.apache.maven.lifecycle.test + project-with-clean-phase-execution + 1.0 + jar + + + + + + org.apache.maven.plugins + maven-clean-plugin + 0.1 + + + org.apache.maven.plugins + maven-compiler-plugin + 0.1 + + + org.apache.maven.plugins + maven-deploy-plugin + 0.1 + + + org.apache.maven.plugins + maven-install-plugin + 0.1 + + + org.apache.maven.plugins + maven-jar-plugin + 0.1 + + + org.apache.maven.plugins + maven-plugin-plugin + 0.1 + + + org.apache.maven.plugins + maven-resources-plugin + 0.1 + + + org.apache.maven.plugins + maven-surefire-plugin + 0.1 + + + + + + org.apache.maven.its.plugins + maven-it-plugin + 0.1 + + + user-clean-execution + clean + + it + + + + + + +