slachiewicz commented on issue #91:
URL: 
https://github.com/apache/maven-reporting-exec/issues/91#issuecomment-7257874399

   I went through the code path behind the duplicated executions in the 
description. Here is what produces them and why a fix inside this component is 
not straightforward.
   
   Each report goal forks separately. 
[DefaultMavenReportExecutor.java:351](https://github.com/apache/maven-reporting-exec/blob/master/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java#L351)
 calls `LifecycleExecutor.calculateForkedExecutions` and [line 
373](https://github.com/apache/maven-reporting-exec/blob/master/src/main/java/org/apache/maven/reporting/exec/DefaultMavenReportExecutor.java#L373)
 calls `executeForkedExecutions` from `prepareReportExecution`, which runs once 
per report goal — `javadoc`, `test-javadoc` and `surefire-report:report` in the 
example. Nothing in the executor records that a phase was already forked for a 
previous goal.
   
   Core builds a fresh plan for each call. In 
[DefaultLifecycleExecutionPlanCalculator.java:295](https://github.com/apache/maven/blob/maven-3.9.x/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java#L295),
 `alreadyForkedExecutions` is a set created per call; it only guards recursion 
inside one fork plan and is popped again at line 341. 
[MojoExecutor.java:416](https://github.com/apache/maven/blob/maven-3.9.x/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java#L416)
 then clones the project into an execution project and runs the whole plan. 
`MavenSession` has no record of which mojos or phases have succeeded, so the 
main `test` lifecycle and each fork cannot see one another. That is why 
`default-resources`, `default-compile` and `default-test` appear again under 
`>>> ... > [surefire]test`.
   
   Skipping a fork because it already ran would break legitimate cases:
   
   - Cobertura-style reports fork a custom lifecycle that instruments classes 
and then runs `test` against them. Reusing the earlier `test` result produces 
an empty coverage file. This is why the earlier MSHARED-266 attempt to fork 
only when `canGenerateReport()` is true was reverted in 
[691714afc9ea220d1e4f442d77011102bb1deaf0](https://github.com/apache/maven-reporting-exec/commit/691714afc9ea220d1e4f442d77011102bb1deaf0).
   - The three requests are different lifecycles (`generate-sources`, 
`generate-test-sources`, `[surefire]test`) with configurations calculated from 
the requesting mojo; deduplicating by plugin, goal and execution id across them 
can drop a mojo a report needs.
   - Aggregator forks span the reactor; non-aggregator forks span one project. 
A shared already-ran key would mix those scopes.
   
   The duplicate was closed as not planned in 
[apache/maven-site-plugin#736](https://github.com/apache/maven-site-plugin/issues/736)
 with the advice to avoid forked lifecycles, and the core side is tracked as 
[MNG-7163](https://github.com/apache/maven/issues/8291). A complete fix needs a 
session-level record of executed mojo executions plus a rule for when a report 
may legitimately request a second run, which belongs in Maven core.
   
   Limits: I read the code and the build log in the description; I did not 
reproduce `clean test site` with cobertura locally. The existing 
`forked-lifecycle` IT passes on `master`, but it only asserts that `site` 
succeeds, not how many times each goal runs.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to