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

Stephen Connolly commented on MNG-5868:
---------------------------------------

Noting for the record, I do not believe that attaching the same artifact 
coordinates multiple times should ever produce a failure, as such I view the 
issue title as incorrect.

This issue seems to be around attaching artifacts using different coordinates 
but which map to the same effective coordinate.

If you have a custom artifact resolver, the type that an artifact ends up being 
deployed as may not be the same as the type with which it was attached, hence 
the simple map that stores the attached artifacts is unaware of the potential 
duplicates and consequently we end up with two artifacts for the same path. 
Harmless for the install plugin, and harmless for the deploy plugin when 
redeployment of artifacts is permitted by the remote repository, but a lot of 
repositories prevent artifact redeployment and the result is a break for them.

Could probably decompose this into two issues:

1. The shade plugin should be consistent with the javadoc and sources plugins 
in how it attaches javadoc and sources artifacts

2. *Either* the deploy plugin should dedup the effective list and only deploy 
the last artifact for any target path *or* core should dedup the artifacts list 
when attaching artifacts.

At no stage should attaching an artifact trigger a build failure IMHO

> Adding serval times the same artifact via MavenProjectHelper (attachArtifact) 
> does not produce a failure 
> ---------------------------------------------------------------------------------------------------------
>
>                 Key: MNG-5868
>                 URL: https://issues.apache.org/jira/browse/MNG-5868
>             Project: Maven
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.3
>            Reporter: Karl Heinz Marbaise
>            Assignee: Karl Heinz Marbaise
>             Fix For: 3.5.1
>
>
> During the check of an issue MSHADE-195 i stumbled over several things...
> If you take a look here and the log output excerpt:
> {noformat}
> INFO] Minimized 2341 -> 1293
> [INFO] Minimized 3282 -> 2234
> [INFO] Replacing original artifact with shaded artifact.
> [INFO] Replacing 
> /Users/kama/ws-git/apache/mshade/mshade-195/target/MSHADE-195-example-1-SNAPSHOT.jar
>  with 
> /Users/kama/ws-git/apache/mshade/mshade-195/target/MSHADE-195-example-1-SNAPSHOT-shaded.jar
> [INFO] Replacing original source artifact with shaded source artifact.
> [INFO] Replacing 
> /Users/kama/ws-git/apache/mshade/mshade-195/target/MSHADE-195-example-1-SNAPSHOT-sources.jar
>  with 
> /Users/kama/ws-git/apache/mshade/mshade-195/target/MSHADE-195-example-1-SNAPSHOT-shaded-sources.jar
> [INFO] Dependency-reduced POM written at: 
> /Users/kama/ws-git/apache/mshade/mshade-195/dependency-reduced-pom.xml
> [INFO]
> [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ 
> MSHADE-195-example ---
> [INFO] Installing 
> /Users/kama/ws-git/apache/mshade/mshade-195/target/MSHADE-195-example-1-SNAPSHOT.jar
>  to 
> /Users/kama/.m2/repository/com/example/MSHADE-195-example/1-SNAPSHOT/MSHADE-195-example-1-SNAPSHOT.jar
> [INFO] Installing 
> /Users/kama/ws-git/apache/mshade/mshade-195/dependency-reduced-pom.xml to 
> /Users/kama/.m2/repository/com/example/MSHADE-195-example/1-SNAPSHOT/MSHADE-195-example-1-SNAPSHOT.pom
> [INFO] Installing 
> /Users/kama/ws-git/apache/mshade/mshade-195/target/MSHADE-195-example-1-SNAPSHOT-sources.jar
>  to 
> /Users/kama/.m2/repository/com/example/MSHADE-195-example/1-SNAPSHOT/MSHADE-195-example-1-SNAPSHOT-sources.jar
> [INFO] Installing 
> /Users/kama/ws-git/apache/mshade/mshade-195/target/MSHADE-195-example-1-SNAPSHOT-sources.jar
>  to 
> /Users/kama/.m2/repository/com/example/MSHADE-195-example/1-SNAPSHOT/MSHADE-195-example-1-SNAPSHOT-sources.jar
> [INFO] 
> {noformat}
> Install plugin tries to install two identical artifacts which will work for 
> maven-install-plugin but would fail a deploy to repository manager (for 
> releases) etc.
> So after diving into the problem i found the following code in maven-core 
> (MavenProject.java):
> {code:java}
>     /**
>      * Add or replace an artifact. This method is now deprecated. Use the 
> @{MavenProjectHelper} to attach artifacts to a
>      * project. In spite of the 'throws' declaration on this API, this method 
> has never thrown an exception since Maven
>      * 3.0.x. Historically, it logged and ignored a second addition of the 
> same g/a/v/c/t. Now it replaces the file for
>      * the artifact, so that plugins (e.g. shade) can change the pathname of 
> the file for a particular set of
>      * coordinates.
>      *
>      * @param artifact the artifact to add or replace.
>      * @throws DuplicateArtifactAttachmentException
>      */
>     public void addAttachedArtifact( Artifact artifact )
>         throws DuplicateArtifactAttachmentException
>     {
>         getAttachedArtifacts().add( artifact );
>     }
>     public List<Artifact> getAttachedArtifacts()
>     {
>         if ( attachedArtifacts == null )
>         {
>             attachedArtifacts = new ArrayList<>();
>         }
>         return attachedArtifacts;
>     }
> {code}
> So taking a look into MavenProjectHelper.java and the implementation 
> (DefaultMavenProjectHelper.java).
> {code:java}
>     /**
>      * Add an attached artifact or replace the file for an existing artifact.
>      *
>      * @see 
> MavenProject#addAttachedArtifact(org.apache.maven.artifact.Artifact)
>      * @param project project reference.
>      * @param artifact artifact to add or replace.
>      */
>     public void attachArtifact( MavenProject project, Artifact artifact )
>     {
>         project.addAttachedArtifact( artifact );
>     }
> {code}
> which means that there is not check if an artifacts is already attached.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to