maven-dependency-plugin
maven-dependency-plugin copied to clipboard
[MDEP-650] dependency:unpack doesn't seem to handle version ranges
Andy Lehane opened MDEP-650 and commented
This call is a reopened version of MDEP-50.
I have a maven-dependency-plugin configuration of:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack commons-lang example</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>[0,)</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/test</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
When this is run using maven 3.6.0 and the maven-dependency-plugin version 3.1.1, the following error is produced:
[INFO] --- maven-dependency-plugin:3.1.1:unpack (unpack commons-lang example) @ MavenDependencyPluginTestBed ---
[INFO] Configured Artifact: common-lang:commons-lang:[0,):jar
Downloading from central-proxy: http://internal-repo/repository/central/commons-lang/commons-lang/%5B0,)/commons-lang-%5B0,).pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ---------------------------------------------------------------
Affects: 3.1.1
Remote Links:
2 votes, 3 watchers
Andy Lehane commented
I've been working on a fix for this, which is based on the following ideas:
AbstractFromConfigurationMojo:
- - Add a new method called, resolveArtifactRanges
- - Call resolveArtifactRanges in the getProcessedArtifactItems method as the first call after the log statement when looping around each artifact item.
- - The resolveArtifactRanges method performs the following logic:
- Constructs a version range from the artifactItem's version property, if the range has no restrictions, no processing is required.
- If the version range has restrictions, then try and find a match in the projects list of already resolved dependencies (i.e. project.getDependencyArtifacts()).
- If the artifact is not found in the project.getDepencencyArtifacts list, then use the Maven DependencyResolver (injected into the Mojo using the
@Componentannotation). - If an artifact has been resolved to a specific version, then update the artifactItem's version property with the resolved version.
- If the artifact cannot be resolved, then leave the version alone (maintaining backwards compatibility)
Andy Lehane commented
I've tested this locally, which works. All of the unit tests pass. I've attempted to write unit tests for the new functionality but keep getting errors when the getArtifact(artifactItem) method attempts to use the artifact resolver to look up the artifact. I assume that I'm not setting up the test correctly but cannot figure out how to do this correctly.
Andy Lehane commented
When I get the unit tests created and working, I'll look to submit a pull request from my github fork.
Andy Lehane commented
I've figured out how to create the unit tests now, so will create the pull request tomorrow.
Joshua Caplan commented
does any other workaround exist? this issue has been open for nearly 3 years, with the fix already provided.