maven-dependency-plugin icon indicating copy to clipboard operation
maven-dependency-plugin copied to clipboard

[MDEP-650] dependency:unpack doesn't seem to handle version ranges

Open jira-importer opened this issue 6 years ago • 6 comments

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

jira-importer avatar Apr 25 '19 12:04 jira-importer

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:
  1. Constructs a version range from the artifactItem's version property, if the range has no restrictions, no processing is required.
  2. If the version range has restrictions, then try and find a match in the projects list of already resolved dependencies (i.e. project.getDependencyArtifacts()).
  3. If the artifact is not found in the project.getDepencencyArtifacts list, then use the Maven DependencyResolver (injected into the Mojo using the @Component annotation). 
  4. If an artifact has been resolved to a specific version, then update the artifactItem's version property with the resolved version.
  5. If the artifact cannot be resolved, then leave the version alone (maintaining backwards compatibility)

 

jira-importer avatar Apr 25 '19 12:04 jira-importer

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.

jira-importer avatar Apr 25 '19 12:04 jira-importer

Andy Lehane commented

When I get the unit tests created and working, I'll look to submit a pull request from my github fork.

jira-importer avatar Apr 25 '19 12:04 jira-importer

Andy Lehane commented

I've figured out how to create the unit tests now, so will create the pull request tomorrow.

jira-importer avatar Apr 25 '19 15:04 jira-importer

Andy Lehane commented

Pull request 12 created (please ignore request 11 as this contained errors).

jira-importer avatar Apr 26 '19 13:04 jira-importer

Joshua Caplan commented

does any other workaround exist? this issue has been open for nearly 3 years, with the fix already provided.

jira-importer avatar Feb 04 '22 01:02 jira-importer