slachiewicz opened a new pull request, #14086:
URL: https://github.com/apache/maven/pull/14086

   Fixes #14081. Master counterpart of #14085 (which targets `maven-4.0.x`).
   
   ## Problem
   
   With `-b concurrent` and more than one thread, a Maven 3 API mojo late in 
one step (e.g. `spring-boot:repackage` in `package`) can see an empty 
`MavenProject.getArtifacts()` because a mojo of a parallel step of the *same* 
project (e.g. `jacoco:report` at `after:test`) replaces the project's resolved 
artifacts in between. The build still reports SUCCESS; the failure only shows 
up at runtime.
   
   ## Cause
   
   `MojoExecutor` creates a fresh `DependencyContext` per build-plan step. 
`DependencyContext.isResolutionRequiredForCurrentProject()` is an 
object-identity check against `MavenProject.getDependencyArtifacts()`, so a 
fresh context with **no scopes** still reports that resolution is required. 
`ensureDependenciesAreResolved` then calls 
`LifecycleDependencyResolver.resolveProjectDependencies` with empty scope 
collections; `getDependencies` returns an empty set and 
`setResolvedArtifacts(empty)` is written to the shared project. The later mojo 
of the first step skips its own resolution (its context still sees unchanged 
`dependencyArtifacts`) and filters that empty set through its own artifact 
filter.
   
   The per-project lock from #13591 serializes individual mojo executions, so 
it cannot protect this step-level assumption.
   
   ## Fix
   
   Skip `resolveProjectDependencies` when the step has neither scopes to 
collect nor scopes to resolve. The check uses `||`, so collection-only mojos 
still resolve. The unconditional `setArtifactFilter(...)` write is left 
completely unchanged: a `null` filter is meaningful for MNG-3297 and must still 
be applied to every Maven 3 mojo.
   
   A regression test (`MojoExecutorEmptyScopeTest`) resolves compile+provided 
artifacts for one step, runs a no-scope step, and asserts that the resolver is 
not called for the empty step and that a later mojo of the original step still 
sees both artifacts. The test fails without this change.
   
   ## Verification
   
   - `impl/maven-core` test suite on the 4.0.x counterpart: 742 tests, 0 
failures, 1 skipped.
   - Reproducer (`-b concurrent -T1C`): detector mojo sees 0 artifacts before, 
1 after.
   - This PR's CI is the gate for master (local checkouts have no network).
   
   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).
   


-- 
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