You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Matt Foley (JIRA)" <ji...@apache.org> on 2018/12/20 19:14:00 UTC

[jira] [Commented] (MSHADE-259) Shade plugin attaches the test jar which causes it deployed twice during release of project

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

Matt Foley commented on MSHADE-259:
-----------------------------------

I encountered this problem while attempting an internal repository deployment of a patched version of Spark; see SPARK-21544 for a thorough description.

There are actually three problems in version 3.2.1 of ShadeMojo::execute() regarding <shadeTestJar>:
 # The shaded test jar is attached as type "jar" instead of the correct "test-jar" type.  This confused the duplicate jars issue, because one copy of the test jar was attached as "org.apache.spark:spark-streaming_2.11:{color:#ff0000}jar{color}:tests:2.4.0-SNAPSHOT" and the other as "org.apache.spark:spark-streaming_2.11:{color:#ff0000}test-jar{color}:tests:2.4.0-SNAPSHOT".  It is documented at [https://maven.apache.org/ref/3.6.0/maven-core/artifact-handlers.html] that the correct artifact type for test jars is "test-jar".
 # When <shadedArtifactAttached> is false, the test jar artifact is nevertheless attached explicitly. This causes the duplicate attachment, because the test jar is already in the attachment list from its original creation. (The same error occurs with createSourcesJar, and is also fixed in the patch.)
 # When <shadedArtifactAttached> is true, the shaded test jar artifact is NOT attached, and it should be.

I am about to file a PR with fixes for the above.

> Shade plugin attaches the test jar which causes it deployed twice during release of project
> -------------------------------------------------------------------------------------------
>
>                 Key: MSHADE-259
>                 URL: https://issues.apache.org/jira/browse/MSHADE-259
>             Project: Maven Shade Plugin
>          Issue Type: Bug
>    Affects Versions: 3.1.0
>            Reporter: Niraj Agarwal
>            Priority: Major
>
> 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.
> {code}
> <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>
> {code}
> Here is the issue/logs captured during release of application project
> {code}
> # 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]
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)