Maven
  1. Maven
  2. MNG-3380

MavenMetadataSource retrieves ResolutionGroup without consulting ManagedVersionMap, is problem when relocation

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.8
    • Fix Version/s: 2.0.10, 2.1.0-M1
    • Component/s: Dependencies
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Number of attachments :
      4

      Description

      Consider the following scenario:

      <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>root-groupId</groupId>
        <artifactId>root-artifactId</artifactId>
        <version>1</version>
        <dependencies>
          <dependency>
            <groupId>direct-dependency-groupId</groupId>
            <artifactId>direct-dependency-artifactId</artifactId>
            <version>1</version>
          </dependency>
        </dependencies>
        <dependencyManagement>
          <dependencies>
            <dependency>
              <groupId>transitive-dependency-new-groupId</groupId>
              <artifactId>transitive-dependency-artifactId</artifactId>
              <version>2</version>
            </dependency>
          </dependencies>
        </dependencyManagement>
      </project>
      
      <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>direct-dependency-groupId</groupId>
        <artifactId>direct-dependency-artifactId</artifactId>
        <version>1</version>
        <dependencies>
          <dependency>
            <groupId>transitive-dependency-old-groupId</groupId>
            <artifactId>transitive-dependency-artifactId</artifactId>
            <version>1</version>
          </dependency>
        </dependencies>
      </project>       
      
             
      <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>transitive-dependency-old-groupId</groupId>
        <artifactId>transitive-dependency-artifactId</artifactId>
        <version>1</version>
        <distributionManagement>
          <relocation>
            <groupId>transitive-dependency-new-groupId</groupId>
          </relocation>
        </distributionManagement>
      </project>       
      
      <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>transitive-dependency-new-groupId</groupId>
        <artifactId>transitive-dependency-artifactId</artifactId>
        <version>1</version>
        <dependencies>
          <dependency>
            <groupId>other-groupId</groupId>
            <artifactId>other-artifactId-a</artifactId>
            <version>1</version>
          </dependency>
        </dependencies>
      </project>
      
      <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>transitive-dependency-new-groupId</groupId>
        <artifactId>transitive-dependency-artifactId</artifactId>
        <version>2</version>
        <dependencies>
          <dependency>
            <groupId>other-groupId</groupId>
            <artifactId>other-artifactId-a</artifactId>
            <version>1</version>
          </dependency>
          <dependency>
            <groupId>other-groupId</groupId>
            <artifactId>other-artifactId-b</artifactId>
            <version>1</version>
          </dependency>
        </dependencies>
      </project>
      
      --------------------------------------------------------------        
      actual dependency:tree 
          
       root-groupId:root-artifactId:jar:1
       \- direct-dependency-groupId:direct-dependency-artifactId:jar:1:compile
          \- transitive-dependency-new-groupId:transitive-dependency-artifactId:jar:2:compile (version managed from 1)
             \- other-groupId:other-artifactId-a:jar:1:compile           
      -------------------------------------------------------------- 
      expected dependency:tree 
          
       root-groupId:root-artifactId:jar:1
       \- direct-dependency-groupId:direct-dependency-artifactId:jar:1:compile
          \- transitive-dependency-new-groupId:transitive-dependency-artifactId:jar:2:compile (version managed from 1)
             \- other-groupId:other-artifactId-a:jar:1:compile    
             \- other-groupId:other-artifactId-b:jar:1:compile <-- missing from actual result    
      -------------------------------------------------------------- 
      

      As you can see from the listing above, other-groupId:other-artifactId-b:jar:1:compile is missing from the dependency list.

      I have attached the zipped repo which was used when generating the dependency:tree listings shown above. I also attached a crude temporary patch which my team is currently using to resolve this issue. After ignoring whitespace changes, it is about 10 lines different.

      Thanks,

      Luke

      1. MNG-3380-maven-artifact.patch
        11 kB
        luke w patterson
      2. patch.txt
        11 kB
        luke w patterson

        Activity

        Hide
        luke w patterson added a comment -

        I attached a new integration test for this condition. (MNG-3380-integration-test.zip)

        The test fails in all of these:

        2.0.7
        2.0.8
        2.0.9
        2.1-SNAPSHOT (rev 649863 of trunk)

        Without a fix, plugins cannot rely on org.apache.maven.project.MavenProject#getArtifacts(). Results could be inaccurate if you use dependencyManagement and have relocated transitive dependencies.

        Summary of integration test:
        ---------------------------------------------------------------
        project.getArtifacts()

        direct-dependency-groupId:direct-dependency-artifactId:jar:1:compile
        transitive-dependency-new-groupId:transitive-dependency-artifactId:jar:2:compile
        other-groupId:other-artifactId-a:jar:1:compile
        other-groupId:other-artifactId-b:jar:1:compile <-- should be here, but isn't
        other-groupId:other-artifactId-c:jar:1:compile <-- is here, but shouldn't be
        ---------------------------------------------------------------

        Show
        luke w patterson added a comment - I attached a new integration test for this condition. ( MNG-3380 -integration-test.zip) The test fails in all of these: 2.0.7 2.0.8 2.0.9 2.1-SNAPSHOT (rev 649863 of trunk) Without a fix, plugins cannot rely on org.apache.maven.project.MavenProject#getArtifacts(). Results could be inaccurate if you use dependencyManagement and have relocated transitive dependencies. Summary of integration test: --------------------------------------------------------------- project.getArtifacts() direct-dependency-groupId:direct-dependency-artifactId:jar:1:compile transitive-dependency-new-groupId:transitive-dependency-artifactId:jar:2:compile other-groupId:other-artifactId-a:jar:1:compile other-groupId:other-artifactId-b:jar:1:compile <-- should be here, but isn't other-groupId:other-artifactId-c:jar:1:compile <-- is here, but shouldn't be ---------------------------------------------------------------
        Hide
        John Casey added a comment -

        This is fixed on the 2.0.x branch, and I've incorporated an integration test based on the MNG-3380-integration-test.zip (I changed it to fail compilation and unit testing, rather than requiring a separate plugin to verify things).

        The only thing that I need to finish up is the fix for trunk (2.1) before I close this issue.

        Show
        John Casey added a comment - This is fixed on the 2.0.x branch, and I've incorporated an integration test based on the MNG-3380 -integration-test.zip (I changed it to fail compilation and unit testing, rather than requiring a separate plugin to verify things). The only thing that I need to finish up is the fix for trunk (2.1) before I close this issue.
        Hide
        John Casey added a comment -

        I modified the artifact collector (and artifact metadata source) to allow the resolution of all project relocations before attempting to resolve the child nodes.

        Show
        John Casey added a comment - I modified the artifact collector (and artifact metadata source) to allow the resolution of all project relocations before attempting to resolve the child nodes.
        Hide
        luke w patterson added a comment -

        I tested with 2.0.10-RC2 [1] the production scenario that originally highlighted this issue. Issue Resolved.

        Thanks for your dedicated effort in moving 2.0.10 along.

        [1] - http://people.apache.org/~jdcasey/stage/apache-maven/2.0.10-RC2

        Show
        luke w patterson added a comment - I tested with 2.0.10-RC2 [1] the production scenario that originally highlighted this issue. Issue Resolved. Thanks for your dedicated effort in moving 2.0.10 along. [1] - http://people.apache.org/~jdcasey/stage/apache-maven/2.0.10-RC2
        Hide
        John Casey added a comment -

        Adding fix-for for both 2.0.10 and 2.1.0-M1, since 2.1.0-M1 will actually be released first and may not incorporate all of the eventual issue fixes released in 2.0.10.

        Show
        John Casey added a comment - Adding fix-for for both 2.0.10 and 2.1.0-M1, since 2.1.0-M1 will actually be released first and may not incorporate all of the eventual issue fixes released in 2.0.10.

          People

          • Assignee:
            John Casey
            Reporter:
            luke w patterson
          • Votes:
            7 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: