Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-7527

Resolving inter-module dependencies does not work like expected

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0-alpha-1
    • None
    • Core
    • None

    Description

      After resolving MNG-4660  ReactorReader picks up packaged main artifact only and ignores supplemental artifacts:

       

       

      private Artifact findMatchingArtifact( MavenProject project, Artifact requestedArtifact )
      {
          String requestedRepositoryConflictId = ArtifactIdUtils.toVersionlessId( requestedArtifact );
      
          Artifact mainArtifact = RepositoryUtils.toArtifact( project.getArtifact() );
          if ( requestedRepositoryConflictId.equals( ArtifactIdUtils.toVersionlessId( mainArtifact ) ) )
          {
              return mainArtifact;
          }
          
          /*
           * if module is not a part of "build reactor", project.getAttachedArtifacts() always
           * returns empty list, it seems that it is plugins' responsibility to populate attached artifacts
           * however it seems no corresponding API has been introduced, which would allow to gather information
           * about supplemental artifacts without building module
           */
          return RepositoryUtils.toArtifacts( project.getAttachedArtifacts() ).stream()
                  .filter( isRequestedArtifact( requestedArtifact ) )
                  .findFirst()
                  .orElse( null );
      } 

       

       

      private File determinePreviouslyPackagedArtifactFile( MavenProject project, Artifact artifact )
      {
          if ( artifact == null )
         
      {         return null;     }
          /*
           * the implementation/signature of this method looks bit confusing: it accepts any artifact descriptor
           * but returns main artifact only, I do believe in some cases (if supplemental artifact got discovered) 
           * it may return wrong file
           */ 
          String fileName = String.format( "%s.%s", project.getBuild().getFinalName(), artifact.getExtension() );
          return new File( project.getBuild().getDirectory(), fileName );
      } 

       

      That new behaviour causes following issues:

      • if extension of main artifact differs from classifier's (e.g. war/classes) ReactorReader fails to pick up artifact (gh link to demo project: https://github.com/andreybpanfilov/MNG-7527)
      • if extension of main artifact does not differ from classifier's ReactorReader picks up wrong artifact 

       

      I have discovered another issue - the `mvn package clean package` command might look insane, however, I do believe it reveals there are some issues with internal state of artifacts/dependencies:

       

      MNG-7527 % ~/app/maven/4.0/bin/mvn package clean package -f mng7527-dep2
      [INFO] Building jar: MNG-7527/mng7527-dep2/target/mng7527-dep2-0.0.1-SNAPSHOT.jar
      [INFO] --------------------------------------------------------------------------------------------------------------------------
      [INFO] BUILD FAILURE
      [INFO] --------------------------------------------------------------------------------------------------------------------------
      [INFO] Total time:  1.063 s
      [INFO] Finished at: 2022-08-08T21:05:18+10:00
      [INFO] --------------------------------------------------------------------------------------------------------------------------
      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:3.2.0:jar (default-jar) on project mng7527-dep2: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them. -> [Help 1]
      [ERROR] 

       

       

      Attachments

        1. MNG-7527.zip
          4 kB
          Andrey Panfilov

        Issue Links

          Activity

            People

              mthmulders Maarten Mulders
              andrew@panfilov.tel Andrey Panfilov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: