You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "sebtiem (via GitHub)" <gi...@apache.org> on 2026/09/25 10:07:33 UTC
[PR] DRAFT: [MNG-5885]: prevent lifecycle phase duplication before execution [maven]
sebtiem opened a new pull request, #13270:
URL: https://github.com/apache/maven/pull/13270
Example implementation, how to avoid duplicate lifecycle execution if a build is started by 'mvn compile verify'.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] DRAFT: [MNG-5885]: prevent lifecycle phase duplication before execution [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13270:
URL: https://github.com/apache/maven/pull/13270#issuecomment-6203265187
Thanks for the contribution @sebtiem!
The use case this PR addresses β preventing lifecycle phase duplication when running overlapping phases like `mvn compile verify` β is already handled by the concurrent builder (`-b concurrent`) via DAG merge semantics in `BuildPlan`. PR #13532 (now merged) further improved the merge logic to correctly handle overlapping task segments, un-skip phases, and prevent cycles.
The approach in this PR (filtering in `DefaultLifecycleExecutionPlanCalculator`) only affects the legacy single-threaded executor and has ordering issues (e.g., `mvn package compile` would silently drop the second `compile`). Given that Maven 4 is moving toward the concurrent builder as the primary execution model, fixing the legacy path is not worth the complexity.
Closing in favor of the concurrent builder's existing solution. The relevant JIRA (MNG-5885) can be resolved as "Won't Fix" or linked to the concurrent builder work.
_Claude Code on behalf of Guillaume Nodet_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] DRAFT: [MNG-5885]: prevent lifecycle phase duplication before execution [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13270:
URL: https://github.com/apache/maven/pull/13270#issuecomment-5834926678
> The concurrent executor (BuildPlanExecutor) handles this correctly via BuildPlan.then() + merge semantics...
To be explicit about this: **the problem described in MNG-5885 is already solved in the concurrent builder** (`BuildPlanExecutor`) as a natural consequence of the DAG merge semantics. When `mvn compile package` is executed with `-T N` (or `--threads`), `then()` merges phase nodes via `putIfAbsent` β nodes already present from `compile` are not re-added when `package` is merged in. The execution plan is identical to `mvn package` without any explicit dedup logic.
This PR therefore only affects the **legacy single-threaded path** (`DefaultLifecycleExecutionPlanCalculator`, flat list, no graph), which is the default for most users who don't pass `--threads`. That's the right place to fix it, but the fix needs to be ordering-aware (see inline comments above) to match the semantics the JIRA requires.
_This comment was generated by an AI agent, Hermès on behalf of @gnodet._
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] DRAFT: [MNG-5885]: prevent lifecycle phase duplication before execution [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet closed pull request #13270: DRAFT: [MNG-5885]: prevent lifecycle phase duplication before execution
URL: https://github.com/apache/maven/pull/13270
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] DRAFT: [MNG-5885]: prevent lifecycle phase duplication before execution [maven]
Posted by "gnodet (via GitHub)" <gi...@apache.org>.
gnodet commented on PR #13270:
URL: https://github.com/apache/maven/pull/13270#issuecomment-6040364524
> The 'optimization' or ordering-aware mechanic is part of the discussion in slack: wether to have it or not. The Jira issue is over 8 years old, therefore I would like to understand if executing lifecycle phases from 'package compile' has any use case.
I don't know any real use case for that. If we don't consider any compatibility issue, I'd be happy with a solution that merges and reorder phases in a lifecycle. The follow-up question however is: what happens if we have `phase1 phase2 phase3` where `phase2` belongs to a different lifecycle. Currently, the lifecycles are not ordered in any other way than what is given on the CLI. If we want to merge `phase1` and `phase3` in the same lifecycle execution, that means we need to choose an order, either `phase1 phase3 phase2`, or `phase2 phase1 phase3`, provided that `phase1 < phase3` in the lifecycle.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] DRAFT: [MNG-5885]: prevent lifecycle phase duplication before execution [maven]
Posted by "sebtiem (via GitHub)" <gi...@apache.org>.
sebtiem commented on PR #13270:
URL: https://github.com/apache/maven/pull/13270#issuecomment-5886038705
The 'optimization' or ordering-aware mechanic is part of the discussion in slack: wether to have it or not. The Jira issue is over 8 years old, therefore I would like to understand if executing lifecycle phases from 'package compile' has any use case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] DRAFT: [MNG-5885]: prevent lifecycle phase duplication before execution [maven]
Posted by "gnodet-bot (via GitHub)" <gi...@apache.org>.
gnodet-bot commented on code in PR #13270:
URL: https://github.com/apache/maven/pull/13270#discussion_r4103535405
##########
impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java:
##########
@@ -234,7 +234,12 @@ public List<MojoExecution> calculateMojoExecutions(MavenSession session, MavenPr
calculateLifecycleMappings(session, project, lifecyclePhase);
for (List<MojoExecution> mojoExecutionsFromLifecycle : phaseToMojoMapping.values()) {
- mojoExecutions.addAll(mojoExecutionsFromLifecycle);
+ List<String> containedLifeCycles = mojoExecutions.stream()
+ .map(MojoExecution::getLifecyclePhase)
+ .toList();
+ mojoExecutions.addAll(mojoExecutionsFromLifecycle.stream()
+ .filter(e -> !containedLifeCycles.contains(e.getLifecyclePhase()))
+ .toList());
Review Comment:
π΄ **Critical β wrong dedup semantics for reverse-order phases.**
The JIRA [MNG-5885](https://issues.apache.org/jira/browse/MNG-5885) explicitly states:
> `package compile` is weird due to its order, but should **not** be optimized.
But this code unconditionally filters out any mojo whose lifecycle phase is already present β regardless of task order. So `mvn package compile` would silently drop the second `compile` because the `package` task already added all phases through `package` (which includes `compile`). The user explicitly asked for `compile` to run again, and this code swallows that intent.
The correct approach would be to deduplicate only when the **later lifecycle task's phases are a subset** of an earlier one (i.e., when the later phase appears earlier in the lifecycle ordering than a phase already processed). Alternatively, track which phases were contributed by each task and only deduplicate within the same lifecycle when a later task's target phase is higher in the lifecycle.
The concurrent executor (`BuildPlanExecutor`) handles this correctly via `BuildPlan.then()` + merge semantics, where each task creates an independent `BuildPlan` that is merged. Consider aligning the legacy executor with the same approach.
##########
impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java:
##########
@@ -234,7 +234,12 @@ public List<MojoExecution> calculateMojoExecutions(MavenSession session, MavenPr
calculateLifecycleMappings(session, project, lifecyclePhase);
for (List<MojoExecution> mojoExecutionsFromLifecycle : phaseToMojoMapping.values()) {
- mojoExecutions.addAll(mojoExecutionsFromLifecycle);
+ List<String> containedLifeCycles = mojoExecutions.stream()
Review Comment:
π‘ **Naming β `containedLifeCycles` is misleading.**
This variable holds lifecycle **phase names** (e.g. `compile`, `test`, `package`), not lifecycle names (e.g. `default`, `clean`, `site`). Should be named `containedPhases` or `processedPhases`. Also, `LifeCycles` uses inconsistent camelCase β Maven codebase consistently uses `lifecycle` (lowercase `c`).
##########
impl/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java:
##########
@@ -234,7 +234,12 @@ public List<MojoExecution> calculateMojoExecutions(MavenSession session, MavenPr
calculateLifecycleMappings(session, project, lifecyclePhase);
for (List<MojoExecution> mojoExecutionsFromLifecycle : phaseToMojoMapping.values()) {
- mojoExecutions.addAll(mojoExecutionsFromLifecycle);
+ List<String> containedLifeCycles = mojoExecutions.stream()
+ .map(MojoExecution::getLifecyclePhase)
+ .toList();
Review Comment:
β οΈ **Performance β `containedLifeCycles` list rebuilt on every inner-loop iteration.**
The `containedLifeCycles` list is rebuilt from scratch on every iteration of the `phaseToMojoMapping.values()` loop. Since `mojoExecutions` only changes between outer-loop iterations (between tasks), this list should be built **once** before the inner `for` loop, not inside it.
Additionally, `List.contains()` is O(n). For a lifecycle with many phases and plugins, this should be a `Set<String>` for O(1) lookups.
```suggestion
Set<String> containedPhases = mojoExecutions.stream()
.map(MojoExecution::getLifecyclePhase)
.collect(java.util.stream.Collectors.toSet());
```
(Moved **before** the `for` loop, and using a `Set` instead of a `List`.)
##########
impl/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java:
##########
@@ -190,6 +190,46 @@ public void testCalculationOfBuildPlanTasksOfTheCleanLifecycleAndTheInstallLifec
.toList());
}
+ // We need to take in multiple lifecycles
+ @Test
+ public void testCalculationOfBuildPlanTasksOfTheVerifyLifecycleAndTheInstallLifecycle() throws Exception {
+ File pom = getProject("project-with-additional-lifecycle-elements");
+ MavenSession session = createMavenSession(pom);
+ assertEquals(
+ "project-with-additional-lifecycle-elements",
+ session.getCurrentProject().getArtifactId());
+ assertEquals("1.0", session.getCurrentProject().getVersion());
+ List<MojoExecution> executionPlan =
+ getExecutions(calculateExecutionPlan(session, "clean", "verify", "install"));
+
+ // [01] clean:clean
+ // [02] resources:resources
+ // [03] compiler:compile
+ // [04] it:generate-metadata
+ // [05] resources:testResources
+ // [06] compiler:testCompile
+ // [07] it:generate-test-metadata
+ // [08] surefire:test
+ // [09] jar:jar
+ // [10] install:install
+ //
+ assertListEquals(
+ List.of(
+ "clean:clean",
+ "resources:resources",
+ "compiler:compile",
+ "it:generate-metadata",
+ "resources:testResources",
+ "compiler:testCompile",
+ "it:generate-test-metadata",
+ "surefire:test",
+ "jar:jar",
+ "install:install"),
+ executionPlan.stream()
+ .map(plan -> plan.getMojoDescriptor().getFullGoalName())
+ .toList());
+ }
+
// We need to take in multiple lifecycles
Review Comment:
β οΈ **Test coverage gap β doesn't test the actual MNG-5885 scenario.**
This test verifies that `clean verify install` deduplicates to the same plan as `clean install`. That's a valid case, but it doesn't test:
1. **The primary JIRA scenario**: `mvn compile package` β two tasks from the same lifecycle where the first is a strict subset. Does the plan equal `mvn package`?
2. **The reverse-order case**: `mvn package compile` β per JIRA, this should **not** be optimized (compile should still execute after package). Does the current code handle this?
3. **The interleaved case**: `mvn compile resources:copy-resources package` β per JIRA, this should run phases up to compile, then the goal, then process-classes through package.
4. **GoalTask + LifecycleTask interaction**: `mvn compiler:compile package` β the GoalTask has `null` lifecyclePhase. Does the null get into `containedLifeCycles` and cause incorrect filtering?
Without these tests, the implementation can't be verified against the actual requirements.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org