Search code examples
mavenmaven-dependency-pluginmaven-metadata

Maven dependency:copy artifact with base version


I'm trying to download some artifacts via command line with maven. I know only the base version of the artifacts, but they have a individual timestamp in the nexus repository.

For example:

The artifact com.mycompany.subject:any-artifact:3.0.0-SNAPSHOT:war:plugins has the following coordinates com.mycompany.subject:any-artifact:3.0.0-20161212.140040-1:war:plugins in the nexus repository.

I want to download the artifact like this:

 mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:copy -Dartifact=com.mycompany.subject:any-artifact:3.0.0-SNAPSHOT:war:plugins -DoutputDirectory=./my-tmp 

I found in the documentation the -Dmdep.useBaseVersion option, but this only saves the downloaded artifact with the base version.

EDIT:

The problem is, that i only know the base version of an artifact e.g. 3.0.0-SNAPSHOT and when i try to download it from nexus like above, it fails, because the version in nexus is with a timestamp.

maven-metadata.xml:

<metadata>
  <groupId>com.mycompany.subject</groupId>
  <artifactId>any-artifact</artifactId>
  <versioning>
    <versions>
        <version>3.0.0-SNAPSHOT</version>
    </versions>
    <lastUpdated>20161214160043</lastUpdated>
  </versioning>
</metadata>

Error-Stacktrace:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.319 s
[INFO] Finished at: 2016-12-19T15:04:06+01:00
[INFO] Final Memory: 16M/298M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:copy (default-cli) on project standalone-pom: Unable to find artifact. Could not find artifact com.mycompany.subject:any-artifact:3.0.0-SNAPSHOT in <remote-repository-id> (https://<nexus-repo-url>/nexus/repository/<specified-repository>)
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId ...
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId ...
[ERROR]
[ERROR]
[ERROR] com.mycompany.subject:any-artifact:3.0.0-SNAPSHOT
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] remote-repository-id (https://<nexus-repo-url>/nexus/repository/<specified-repository>),
[ERROR] -> [Help 1]

Solution

  • The problem is that the project doesn't have a pom.xml in the repository, therefore maven needs probably the exact version number with timestamp etc.

    Now, i deploy the artifacts with the -DgeneratePom=true option and i can download the latest artifacts from the repository only with the base version number.