Fix #2576: -itr option not working in Maven 4 #5541
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the
-itr
(ignore transitive repositories) option not working in Maven 4.Problem
The
-itr
command line option was not working in Maven 4 because the newArtifactDescriptorReaderDelegate
implementation inmaven-impl
was unconditionally adding repositories from dependency POMs without checking theignoreArtifactDescriptorRepositories
setting.While the CLI option was properly parsed and the setting was correctly passed through the execution request to the repository session, the new implementation ignored this flag.
Root Cause
In
impl/maven-impl/src/main/java/org/apache/maven/impl/resolver/ArtifactDescriptorReaderDelegate.java
, thepopulateResult()
method was always adding repositories from the model without checking ifsession.getSession().isIgnoreArtifactDescriptorRepositories()
was enabled.The deprecated compat layer (
maven-resolver-provider
) correctly implemented this check, but the new Maven 4 implementation was missing it.Solution
Code Changes
ignoreArtifactDescriptorRepositories
inArtifactDescriptorReaderDelegate.populateResult()
MavenITgh2576IgnoreTransitiveRepositoriesTest
to verify the fix worksTestSuiteOrdering
to include the new test at the topTest Strategy
The integration test creates a scenario where:
-itr
: Build succeeds (transitive repository is used)-itr
: Build fails (transitive repository is ignored)This verifies that the
-itr
option correctly ignores repositories declared in dependency POMs.Files Changed
impl/maven-impl/src/main/java/org/apache/maven/impl/resolver/ArtifactDescriptorReaderDelegate.java
- Added missing checkits/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh2576IgnoreTransitiveRepositoriesTest.java
- New integration testits/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
- Added test to orderingits/core-it-suite/src/test/resources/gh-2576-ignore-transitive-repositories/
- Test resourcesTesting
gh-
prefix for GitHub issuesTestSuiteOrdering
at the topCode Review Notes
The fix is minimal and surgical - it only adds the missing conditional check that was present in the deprecated compat layer but missing in the new Maven 4 implementation. The integration test comprehensively verifies the functionality works as expected.
Fixes #2576
Pull Request opened by Augment Code with guidance from the PR author