arturobernalg opened a new pull request, #13591: URL: https://github.com/apache/maven/pull/13591
## What and why With `-b concurrent` and two or more threads the compiler can receive a classpath without the `provided` dependencies when another mojo of the project runs at about the same time, for instance `flatten-maven-plugin` in `process-resources` (#13590). Before a mojo is executed, `MojoExecutor#ensureDependenciesAreResolved` prepares its dependencies by replacing the resolved artifacts and the artifact filter of the shared `MavenProject`, and the mojo reads them when it is configured. This is done for every mojo, also for the ones that need no dependency, which get an empty filter. The concurrent executor does not use a project lock, so a mojo could be configured with the artifacts prepared for another one. I found this by logging `setResolvedArtifacts` and `setArtifactFilter`: a mojo without dependencies set an empty filter on the project while the compiler, which held no lock against it, was starting. ## How The concurrent `MojoExecutor` takes a per-project lock, kept in the session data, around the preparation and the execution of every mojo. Executions of different projects still run in parallel. An earlier attempt that locked only the mojos which declare a resolution or collection requirement was not enough: it went from 0 to 10 successful runs out of 12, the mojos without requirements being the remaining cause. ## Tests `MojoExecutorTest` checks that two executions of the same project do not overlap and that executions of different projects do. `maven-core` passes (762 tests) and spotless is clean. I also built the distribution and ran a reactor of four modules, each with `jakarta.ws.rs-api` in `provided` scope and `flatten-maven-plugin` in `process-resources`. `mvn -b concurrent -T 4 package` failed 12 times out of 12 on master and passed 20 times out of 20 with this change. I did not run the integration tests. --- To make clear that you license your contribution under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0) check one of the following: - [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0) - [x] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf). -- 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]
