[ 
https://issues.apache.org/jira/browse/MNG-7527?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17584528#comment-17584528
 ] 

Andrey Panfilov commented on MNG-7527:
--------------------------------------

[~mthmulders] 

The purpose of demo project provided is to demonstrate the issue: maven fails 
to discover packaged supplemental artifacts while they do exist in project 
workspace. Adding sources doesn't make sense: maven still fails to discover 
packaged supplemental artifacts however in that case in returns output 
directory instead of the packaged artifact, that might be helpful for 
compiling, but totally unusable for other scenarios.

> Resolving inter-module dependencies does not work like expected
> ---------------------------------------------------------------
>
>                 Key: MNG-7527
>                 URL: https://issues.apache.org/jira/browse/MNG-7527
>             Project: Maven
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 4.0.0-alpha-1
>            Reporter: Andrey Panfilov
>            Assignee: Maarten Mulders
>            Priority: Major
>         Attachments: MNG-7527.zip
>
>
> After resolving MNG-4660  ReactorReader picks up packaged main artifact only 
> and ignores supplemental artifacts:
>  
>  
> {code:java}
> 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 );
> } {code}
>  
>  
> {code:java}
> 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 );
> } {code}
>  
> 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:
>  
> {code:java}
> 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] {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to