Skip to content

[MNG-5404] Wrong resolution of dependency scope by Maven 3 #6521

Open

Description

@jira-importer

Dmitry Batrak opened MNG-5404 and commented

For the following POM:

<project> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>test</groupId> 
    <artifactId>A</artifactId> 
    <version>1.0</version> 

    <dependencies> 
        <dependency> 
            <groupId>org.apache.axis2</groupId> 
            <artifactId>axis2-xmlbeans</artifactId> 
            <version>1.5</version> 
            <scope>provided</scope> 
        </dependency> 
        <dependency> 
            <groupId>org.apache.axis2</groupId> 
            <artifactId>axis2-codegen</artifactId> 
            <version>1.5</version> 
            <exclusions> 
                <exclusion> 
                    <groupId>org.apache.geronimo.specs</groupId> 
                    <artifactId>geronimo-stax-api_1.0_spec</artifactId> 
                </exclusion> 
            </exclusions> 
        </dependency> 
    </dependencies> 
</project> 

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.

Debug log is attached.


Affects: 3.0.4

Attachments:

Issue Links:

  • MNG-5622 Provided dependencies updated to 'compile' even when excluded

Backported to: needing-scrub-3.4.0-fallout

2 votes, 7 watchers

Activity

  1. jira-importer commented on Apr 25, 2013

    @jira-importer
    Author

    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. :-)

  2. jira-importer commented on Apr 26, 2013

    @jira-importer
    Author

    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.

  3. jira-importer commented on Jan 24, 2014

    @jira-importer
    Author

    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.

  4. jira-importer commented on Jan 12, 2016

    @jira-importer
    Author

    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

    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
    

    Adding my replicator for the bug. Use as:

    mvn -X -f provided.xml dependency:tree
    mvn -X -f compile.xml dependency:tree
    

    Also, adding -Dverbose option to the compile.xml POM stops the scope upgrade.

  5. added
    bug
    priority:major
    on Jul 6, 2025
  6. modified the milestones: , 4.0.0 on Jul 7, 2025
  7. gnodet commented on Mar 23, 2026

    @gnodet
    Contributor

    Status: Still reproducible on Maven 4.1.0-SNAPSHOT

    Tested with the original scenario from the issue report:

    <dependencies>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-xmlbeans</artifactId>
            <version>1.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-codegen</artifactId>
            <version>1.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.geronimo.specs</groupId>
                    <artifactId>geronimo-stax-api_1.0_spec</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    mvn dependency:tree output:

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

    Claude Code on behalf of Guillaume Nodet

  8. modified the milestones: 4.0.0, 4.1.0 on Mar 23, 2026
  9. cstamas commented on Mar 23, 2026

    @cstamas
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority:major

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions