Maven release plugin fails : source artifacts getting deployed twice

后端 未结 12 1715
故里飘歌
故里飘歌 2020-11-28 22:04

We are using the maven release plugin on hudson and trying to automate the release process. The release:prepare works fine. When we try to do the release:perform , it fails

相关标签:
12条回答
  • 2020-11-28 22:29

    TL;DR

    Disable execution with id attach-sources fixes this problem, if you cannot modify your parent poms.

    --

    This answer is a supplementary for @Bae's answer:

    https://stackoverflow.com/a/10794985/3395456

    My problem is the same, when running mvn -Prelease-profile help:effective-pom, I have two execution sections for maven-source-plugin

    <plugin>
      <artifactId>maven-source-plugin</artifactId>
      <version>2.0.4</version>
      <executions>
        <execution>
          <id>attach-sources</id>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
        <execution>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    

    The top voted answer just recommends a best practice to remove unnamed (anonymous) execution to avoid duplicated binding. But what if I cannot remove it, because I cannot change the parent pom?

    There is one way to disable one execution, not the anonymous one, but the one with id attach-source. And it also works for uploading xx-javadoc.jar twice.

    So under my pom.xml, I can explictly override the plugins settings, by disabling the execution with id attach-source.

      <!-- Fix uploading xx-source.jar and xx-javadoc.jar twice to Nexus -->
      <!-- try to disable attach-sources, attach-javadocs execution (bind its phase to none) -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-sources</id>
            <phase>none</phase>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-javadocs</id>
            <phase>none</phase>
          </execution>
        </executions>
        <inherited>true</inherited>
      </plugin>
    

    References: Is it possible to override executions in maven pluginManagement?

    0 讨论(0)
  • 2020-11-28 22:29

    I configured the maven release plug-in with releaseProfile=false and dont execute the source artifacts profile. Which did the trick.

    <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-release-plugin</artifactId>
                        <version>2.1</version>
                        <configuration>
                                <arguments>-P!source-artifacts</arguments>
                                <useReleaseProfile>false</useReleaseProfile>
                                <goals>-Dmaven.test.skip=true deploy</goals>
                        </configuration>    
                    </plugin>
                </plugins>
            </build>
    
    0 讨论(0)
  • 2020-11-28 22:31

    Just having hit the same problem, I analyzed it a bit. mvn release:perform evaluates the release.properties file, then checks out the tag in a temporary directory and invokes there something like

    /usr/bin/mvn -D maven.repo.local=... -s /tmp/release-settings5747060794.xml
        -D performRelease=true -P set-envs,maven,set-envs deploy
    

    I tried to reproduce this – manually checked out the tag produced by release:prepare and invoked this:

    mvn -D performRelease=true -P set-envs,maven,set-envs deploy
    

    I got the same result: It was trying to upload the -sources.jar twice.

    As noted by qualidafial in a comment, setting performRelease=false instead omits one of the two attachments of the same file.

    I don't really have an idea how the deploy plugin (or any other plugin) uses this property.

    We can provide this parameter as a configuration to the maven-relase-plugin:

    <build>
        <plugins>
             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <useReleaseProfile>false</useReleaseProfile>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    I now added the <useReleaseProfile>false</useReleaseProfile> line to all the POMs, and it looks like releasing now works without an error message.

    0 讨论(0)
  • 2020-11-28 22:32

    I know this question is old but it was google hit #1 today so I'll add my answer appropriate for recent versions of maven 3.

    The symptom is that sources and javadoc jars are deployed twice when doing a release build with some versions of maven 3. If you're using maven to deploy your artifacts to a Sonatype Nexus repository that only allows a release artifact to be uploaded once (which is totally reasonable behavior), the build fails when the second upload attempt is rejected. Argh!

    Maven versions 3.2.3 thru 3.3.9 have bugs - see https://issues.apache.org/jira/browse/MNG-5868 and https://issues.apache.org/jira/browse/MNG-5939. Those versions generate and deploy sources and javadoc jars twice when doing a release.

    If I read the Maven issue tracker correctly, those bugs are not scheduled for fix as of this writing (the burned 3.4.0 release probably affected these).

    Instead of a complex tweak to my pom, my simple workaround was to fall back to Maven version 3.2.1.

    0 讨论(0)
  • 2020-11-28 22:32

    Maven plugins in parent and child poms should not have execution. As per standard convention, define all plugin with execution/goals in parent pom in plugin management section. Child pom should not redefine above details, but mention only the plugin (with artifactId, and version) that needs to be executed.

    I had similar issue with maven-assembly-plugin with parent pom as below:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <descriptors>
                            <descriptor>src/assembly/assembly.xml</descriptor>
                        </descriptors>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    

    And Child pom had maven-assembly-plugin as below:

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-5</version>
                <configuration>
                    <finalName>xyz</finalName>
                    <descriptors>
                        <descriptor>src/assembly/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>xyz-distribution</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    Removing the <executions> from child pom rectified the issue. The effective pom had 2 executions performed causing the duplicate install to Nexus repo.

    0 讨论(0)
  • 2020-11-28 22:33

    This was happening to me when running

    mvn install deploy
    

    I avoided the problem by instead running

    mvn deploy
    

    (which implies install). In my case only one artifact was being attempted to be uploaded twice, and that was a secondary artifact (maven-jar-plugin was setup to build a secondary jar in addition to the one built by the default-jar execution).

    0 讨论(0)
提交回复
热议问题