Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.1.2
-
None
-
None
Description
If an existing artifact which has other types (e.g. test-jar) needs to be unpacked the type attribute is getting ignored. Always jar type used.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.1.2</version> <executions> <execution> <id>share-tests</id> <phase>generate-test-sources</phase> <goals> <goal>unpack</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>io.github.zforgo.stackoverflow</groupId> <artifactId>shared-tests</artifactId> <version>0.1.0-SNAPSHOT</version> <type>test-jar</type> <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin>
While running mvn install the log says
[INFO] [INFO] --- maven-dependency-plugin:3.1.2:unpack (share-tests) @ project --- [INFO] Configured Artifact: io.github.zforgo.stackoverflow:shared-tests:0.1.0-SNAPSHOT:test-jar [INFO] Unpacking [...] shared-tests/0.1.0-SNAPSHOT/shared-tests-0.1.0-SNAPSHOT.jar to [...] with includes "" and excludes "" [INFO]
It seems ArtifactItem was configured well but the Artifact is wrong.
After some debugging it seems AbstractFromConfigurationMojo didn't set type attribute when creating Artifact from ArtifactItem.
Related code:
protected Artifact getArtifact( ArtifactItem artifactItem ) throws MojoExecutionException { Artifact artifact; try { // ... ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest(); if ( localRepositoryDirectory != null ) { buildingRequest = repositoryManager.setLocalRepositoryBasedir( buildingRequest, localRepositoryDirectory ); } // Map dependency to artifact coordinate DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate(); coordinate.setGroupId( artifactItem.getGroupId() ); coordinate.setArtifactId( artifactItem.getArtifactId() ); coordinate.setVersion( artifactItem.getVersion() ); coordinate.setClassifier( artifactItem.getClassifier() ); final String extension; ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler( artifactItem.getType() ); //... } catch ( ArtifactResolverException e ) { throw new MojoExecutionException( "Unable to find/resolve artifact.", e ); } return artifact; }
The DefaultArtifactCoordinate sets type to jar and there is no place where it was updated. Because of this wrong artifact will be unpacked.