[ https://issues.apache.org/jira/browse/MNG-7527?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17584340#comment-17584340 ]
Maarten Mulders commented on MNG-7527: -------------------------------------- I believe it should even work with an initial {{mvn compile}} (rather than {{mvn package}}. If the modules actually do contain code, a {{target/classes/}} folder will get generated and Maven will pick that one up when compiling {{dep1}} or {{dep2}}. This works as expected, as far as I can tell. When there's no code (as in your example), you indeed need {{mvn package}} for a {{target/}} folder to be generated. But a module without code would usually have type {{pom}}. Out of curiosity, what is your use case for "empty" modules as a dependency? > 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)