You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MNG-5404] Wrong resolution of dependency scope by Maven 3 #6521
running 'mvn dependency:resolve' using Maven 3.0.4 yields a wrong result.
Namely, geronimo-stax-api_1.0_spec dependency is reported as having the resolved scope of 'compile'. With Maven 2.2.1 I get the 'provided' scope, as expected.
I'm not sure which one should be respected. Let's assume that the result should be "provided", as you pointed out.
Note then, that "mvn dependency:tree" displays the correct result. After some investigation, I found that this is because DefaultDependencyTreeBuilder uses DefaultArtifactCollector (in the "maven-artifact" project) that does some scope update (has a method checkScopeUpdate(...), etc.).
However, the AbstractDependencyFilterMojo (which is the non-direct base class of ResolveDependenciesMojo that is called on "mvn dependency:resolve") relies on "project.getArtifacts()" filled previously by the DefaultProjectDependenciesResolver, which in turn, calls Aether's DefaultRepositorySystem.resolveDependencies(...) method.
This method resolves the scope conflict in question as "compile" so I guess Aether implements it a different way.
Note that there are several issues (such as MNG-5188 and MNG-5145) that are related to dependency scope resolution.
Actually, I'm not that familiar with the code, I was just debugging to see how it works. :-)
Please note that in the above example geronimo-stax-api_1.0_spec is explicitly excluded from transitive dependencies of axis2-codegen, so I don't expect its scope in that path to have any effect on the resulting scope.
I've already shown pom.xml with which the issue can be reproduced, nothing else is required. Just in case you need the same as a file in a zip archive, I'm attaching it.
+- org.apache.axis2:axis2-xmlbeans:jar:1.5:provided
| +- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0.1:compile ← should be provided
\- org.apache.axis2:axis2-codegen:jar:1.5:compile
The geronimo-stax-api_1.0_spec is resolved as compile but should be provided. The only non-excluded path to this artifact is through axis2-xmlbeans (scope provided), so the effective scope should be provided.
This appears to be a Maven Resolver issue in how exclusions interact with scope mediation — the excluded path's scope (compile via axis2-codegen) is being used instead of the surviving path's scope (provided via axis2-xmlbeans).
Moving to 4.1.0 as this is a long-standing resolver behavior issue that needs careful investigation in Maven Resolver 2.0.
Activity
jira-importer commentedon Apr 25, 2013
Robert Balazsi commented
I've found two documents with mutually exclusive specifications regarding this:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope -> nearest="provided", farthest="compile" => result="provided" (as you described)
http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-Scoperesolution -> ... => result="compile"
I'm not sure which one should be respected. Let's assume that the result should be "provided", as you pointed out.
Note then, that "mvn dependency:tree" displays the correct result. After some investigation, I found that this is because DefaultDependencyTreeBuilder uses DefaultArtifactCollector (in the "maven-artifact" project) that does some scope update (has a method checkScopeUpdate(...), etc.).
However, the AbstractDependencyFilterMojo (which is the non-direct base class of ResolveDependenciesMojo that is called on "mvn dependency:resolve") relies on "project.getArtifacts()" filled previously by the DefaultProjectDependenciesResolver, which in turn, calls Aether's DefaultRepositorySystem.resolveDependencies(...) method.
This method resolves the scope conflict in question as "compile" so I guess Aether implements it a different way.
Note that there are several issues (such as MNG-5188 and MNG-5145) that are related to dependency scope resolution.
Actually, I'm not that familiar with the code, I was just debugging to see how it works. :-)
jira-importer commentedon Apr 26, 2013
Dmitry Batrak commented
Please note that in the above example geronimo-stax-api_1.0_spec is explicitly excluded from transitive dependencies of axis2-codegen, so I don't expect its scope in that path to have any effect on the resulting scope.
jira-importer commentedon Jan 23, 2014
Jason van Zyl commented
Please read https://cwiki.apache.org/confluence/display/MAVEN/Submitting+Issue+for+Maven%27s+Core
jira-importer commentedon Jan 24, 2014
Dmitry Batrak commented
I've already shown pom.xml with which the issue can be reproduced, nothing else is required. Just in case you need the same as a file in a zip archive, I'm attaching it.
jira-importer commentedon Jan 12, 2016
Renat Sabitov commented
I also can see this in Maven 3.3.9.
What I noticed is that the scope stopped being upgraded to compile if you exclude everything from the compile scoped dependency via
Adding my replicator for the bug. Use as:
Also, adding -Dverbose option to the compile.xml POM stops the scope upgrade.
gnodet commentedon Mar 23, 2026
Status: Still reproducible on Maven 4.1.0-SNAPSHOT
Tested with the original scenario from the issue report:
mvn dependency:treeoutput:The
geronimo-stax-api_1.0_specis resolved ascompilebut should beprovided. The only non-excluded path to this artifact is throughaxis2-xmlbeans(scopeprovided), so the effective scope should beprovided.This appears to be a Maven Resolver issue in how exclusions interact with scope mediation — the excluded path's scope (
compileviaaxis2-codegen) is being used instead of the surviving path's scope (providedviaaxis2-xmlbeans).Moving to 4.1.0 as this is a long-standing resolver behavior issue that needs careful investigation in Maven Resolver 2.0.
Claude Code on behalf of Guillaume Nodet
cstamas commentedon Mar 23, 2026
I concur, the Resolver 1.x and 2.x behave the same: https://gist.github.com/cstamas/2601f525461a129d175a820190f107c7