Uploaded image for project: 'Maven Shade Plugin'
  1. Maven Shade Plugin
  2. MSHADE-259

Shade plugin attaches the test jar which causes it deployed twice during release of project

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.1.0
    • Fix Version/s: None
    • Labels:
      None

      Description

      When using shade plugin to relocate the packages of a dependency for an application maven project for main artifact as well as test jar (using option shadeTestJar), it attaches the test-jar using projectHelper.attachArtifact( project, "jar", "tests", shadedTests ), this causes the duplicate entry of test artifact which causes issues (build failure) during release as maven-deploy-plugin tries to deploy the test-jar twice to nexus which causes the 2nd deploy fail.

      To shade the test jar I need to add maven-jar-plugin with goal test-jar so that a test jar is created which then can be used by shade plugin to perform the shading and relocation of packages in the test jar. maven-jar-plugin itself also attaches the test-jar artifact.

      Here is the section of the pom.xml file which was used to create the test-jar, shade it and then deploy it.

      <plugin>
      	<groupId>org.apache.maven.plugins</groupId>
      	<artifactId>maven-jar-plugin</artifactId>
      	<version>3.0.2</version>
      	<executions>
      		<execution>
      			<phase>package</phase>
      			<goals>
      				<goal>test-jar</goal>
      			</goals>
      		</execution>
      	</executions>
      </plugin>
      <plugin>
      	<groupId>org.apache.maven.plugins</groupId>
      	<artifactId>maven-shade-plugin</artifactId>
      	<version>3.1.0</version>
      	<executions>
      		<execution>
      			<phase>package</phase>
      			<goals>
      				<goal>shade</goal>
      			</goals>
      		</execution>
      	</executions>
      	<configuration>
      		<shadeTestJar>true</shadeTestJar>
      		<minimizeJar>false</minimizeJar>
      		<createDependencyReducedPom>false</createDependencyReducedPom>
      		<createSourcesJar>false</createSourcesJar>
      		<artifactSet>
      			<includes>
      				<include>com.google.code.gson:gson</include>
      			</includes>
      		</artifactSet>
      		<relocations>
      			<relocation>
      				<pattern>com.google.gson</pattern>
      				<shadedPattern>io.sample.shaded.com.google.gson</shadedPattern>
      			</relocation>
      		</relocations>
      	</configuration>
      </plugin>
      <plugin>
      	<groupId>org.apache.maven.plugins</groupId>
      	<artifactId>maven-deploy-plugin</artifactId>
      	<version>2.8.2</version>
      	<configuration>
      		<deployAtEnd>true</deployAtEnd>
      	</configuration>
      </plugin>
      

      Here is the issue/logs captured during release of application project

      # maven-jar-plugin attaches following test artifact to maven project
      artifact:io.sample:sample-app:test-jar:tests:1.0.0
      
      # maven-shade-plugin attaches following test artifact to maven project
      artifact:io.sample:sample-app:jar:tests:1.0.0
      
      # maven-deploy-plugin tries to deploy the above 2 test artifacts to nexus and fails on 2nd deploy
      [INFO] [INFO] Uploading: http://maven-nexus.mycompany.com/nexus/content/repositories/releases/io/sample/sample-app/1.0.0/sample-app-1.0.0-tests.jar
      [INFO] [INFO] Uploaded: http://maven-nexus.mycompany.com/nexus/content/repositories/releases/io/sample/sample-app/1.0.0/sample-app-1.0.0-tests.jar (233 KB at 3412.8 KB/sec)
      [INFO] [INFO] Uploading: http://maven-nexus.mycompany.com/nexus/content/repositories/releases/io/sample/sample-app/1.0.0/sample-app-1.0.0-tests.jar
      [INFO] [INFO] ------------------------------------------------------------------------
      [INFO] [INFO] Reactor Summary:
      [INFO] [INFO] 
      [INFO] [INFO] sample-app ........................ FAILURE [  5.283 s]
      [INFO] [INFO] ------------------------------------------------------------------------
      [INFO] [INFO] BUILD FAILURE
      [INFO] [INFO] ------------------------------------------------------------------------
      [INFO] [INFO] Total time: 05:01 min
      [INFO] [INFO] Finished at: 2017-08-23T22:13:55+00:00
      [INFO] [INFO] Final Memory: 160M/1167M
      [INFO] [INFO] ------------------------------------------------------------------------
      [INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project sample-app: Failed to deploy artifacts: Could not transfer artifact io.sample:sample-app:jar:tests:1.0.0 from/to releases (http://maven-nexus.mycompany.com/nexus/content/repositories/releases): Failed to transfer file: http://maven-nexus.mycompany.com/nexus/content/repositories/releases/io/sample/sample-app/1.0.0/sample-app-1.0.0-tests.jar. Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                nagarwal Nishith Agarwal
              • Votes:
                2 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m