download of a Maven artifact with dependencies from Nexus using the command line

10,071

Solution 1

jar-with-dependencies in this case is a Maven classifier:

The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.

That is, the 1.0.4 jar and its with-dependencies variant differ in their Maven coordinates via the classifier.

Hence, using the maven-dependency-plugin and its get goal you can specify a classifier via the classifier option:

The classifier of the artifact to download. Ignored if artifact is used.

However, you are indeed using the artifact option already, hence the option above will be ignored as per documentation.
If you look at the documentation of the artifact option though:

A string of the form groupId:artifactId:version[:packaging][:classifier].

Look at its last (optional) token, [:classifier]. This is exactly what you are missing.

Your artifact option should be as following:

-Dartifact=bits:update-service:1.0.4:jar:jar-with-dependencies

Note: you actually already used it incorrectly when specifying:

-Dartifact=bits:update-service:1.0.3[:packaging[:jar]]

The squared brackets [..] indicates optional parameters, you should not specify them in your command line invocation. Moreover the packaging string there specify what value to put: again, you should not specify it, but just replace it with the corresponding value (in this case jar).

Solution 2

I have created an example to show you the way.
I would like to download all the dependencies of spring-webmvc in version 4.2.5.RELEASE.
1) You need the pom of webmvc if not already in your local repository. If spring-webmvc is already in the local repo then skip 1).
2) You can download all the dependencies related to the pom your have just downloaded.

  1. downloading of the pom

C:\temp\spring_web_mvc>mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get -DgroupId=org.springframework -DartifactId=spring-webmvc -Dversion=4.2.5.RELEASE -Dtype=pom

  1. downloading all the dependencies

C:\temp\spring_web_mvc>mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies -f C:\repository2\org\springframework\spring-webmvc\4.2.5.RELEASE\spring-webmvc-4.2.5.RELEASE.pom -DoutputDirectory=C:\TEMP

[INFO] Scanning for projects...
[WARNING] Some problems were encountered while building the effective model for org.springframework:spring-webmvc:jar:4.2.5.RELEASE
...
[INFO] ------------------------------------------------------------------------
[INFO] Building Spring Web MVC 4.2.5.RELEASE
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.lowagie:itext:jar:2.1.7.js4 is missing, no dependency information available
[INFO]
[INFO] --- maven-dependency-plugin:2.10:copy-dependencies (default-cli) @ spring-webmvc ---
[WARNING] The POM for org.apache.maven.doxia:doxia-sink-api:jar:1.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] org.apache.tiles:tiles-request-mustache:jar:1.0.6 already exists in destination.
[INFO] com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.6.5 already exists in destination.
[INFO] org.apache.tiles:tiles-mvel:jar:3.0.5 already exists in destination.
[INFO] org.apache.tiles:tiles-jsp:jar:2.2.2 already exists in destination.
[INFO] org.jfree:jcommon:jar:1.0.23 already exists in destination.
...
[INFO] org.apache.tiles:tiles-extras:jar:3.0.5 already exists in destination.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.095 s
[INFO] Finished at: 2016-06-23T11:06:03+02:00
[INFO] Final Memory: 14M/241M
[INFO] ------------------------------------------------------------------------

Results:

C:\temp\spring_web_mvc>dir
Volume in drive C has no label.
Volume Serial Number is F400-3CE5

Directory of C:\temp\spring_web_mvc

23/06/2016 11:05 .
23/06/2016 11:05 ..
23/06/2016 10:24 4,467 aopalliance-1.0.jar
23/06/2016 10:24 192,035 bcmail-jdk14-1.38.jar
23/06/2016 10:24 192,035 bcmail-jdk14-138.jar ...

Share:
10,071

Related videos on Youtube

AnOldSoul
Author by

AnOldSoul

It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so!

Updated on June 04, 2022

Comments

  • AnOldSoul
    AnOldSoul almost 2 years

    I'm using the command below to download a maven jar from Nexus through the command line.

    call mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -DrepoUrl=http://10.101.15.190:8081/nexus/content/repositories/releases/ -Dartifact=bits:update-service:1.0.3 -Ddest=Setups/Services/update-service.jar
    

    But what I get is a jar without dependencies. There is already a jar with dependencies in Maven with the name update-service-1.0.4-jar-with-dependencies.jar

    I tried the following:

    call mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -DrepoUrl=http://10.101.15.190:8081/nexus/content/repositories/releases/ -Dartifact=bits:update-service:1.0.3[:packaging[:jar]] -Ddest=Setups/Services/update-service.jar
    

    But it returns the following error:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.4:get (default-cli) on project standalone-pom: Couldn't download artifact: Missing:
    [ERROR] ----------
    [ERROR] 1) bits:update-service:packaging[:jar]]:1.0.3[
    [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=bits -DartifactId=update-service -Dversion=1.0.3[ -Dclassifier=jar]] -Dpackaging=packaging[ -Dfile=/path/to/file
    [ERROR]
    [ERROR] Alternatively, if you host your own repository you can deploy the file there:
    [ERROR] mvn deploy:deploy-file -DgroupId=bits -DartifactId=update-service -Dversion=1.0.3[ -Dclassifier=jar]] -Dpackaging=packaging[ -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
    [ERROR]
    [ERROR] Path to dependency:
    [ERROR] 1) org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
    [ERROR] 2) bits:update-service:packaging[:jar]]:1.0.3[
    [ERROR]
    [ERROR] ----------
    [ERROR] 1 required artifact is missing.
    [ERROR]
    [ERROR] for artifact:
    [ERROR] org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
    [ERROR]
    [ERROR] from the specified remote repositories:
    [ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false),
    [ERROR] temp (http://10.101.15.190:8081/nexus/content/repositories/releases/, releases=true, snapshots=true)
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    

    Question: What is the correct way to download a jar with dependencies?