apache / apache/maven-dependency-plugin

[MDEP-732] unpack - artifactItem type attribute ignored

Open
#1,244 1 comment 0 reactions 0 assignees View on GitHub
bug priority:major
Dominant language
Java
Stars
175
Forks
196
Avg merge
19h 30m
Merged PRs (30d)
5

Description

**[Zoltán Forgó](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=zforgo)** opened **[MDEP-732](https://issues.apache.org/jira/browse/MDEP-732?redirect=false)** and commented

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.

```xml

org.apache.maven.plugins
maven-dependency-plugin
3.1.2


share-tests
generate-test-sources

unpack




io.github.zforgo.stackoverflow
shared-tests
0.1.0-SNAPSHOT
test-jar
${project.build.directory}/alternateLocation




```

 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:

```java
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.

---

**Affects:** 3.1.2

2 votes, 3 watchers

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at AbstractFromConfigurationMojo.getArtifact, using the reported artifactItem configuration and the DefaultArtifactCoordinate setup as the entry point. Reproduce the unpack goal with type=test-jar and inspect the resolved artifact. Done means the configured type is honored and the test-jar is unpacked instead of the jar.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.