Jay Taylor's notes

back to listing index

A simple command line to download a remote maven2 artifact to the local repository?

[web search]
Original source (stackoverflow.com)
Tags: java jvm howto maven stackoverflow.com
Clipped on: 2016-11-04

I have a library that I distribute using maven 2. The typical user of this library doesn't use maven to build their applications, but is likely somewhat familiar with maven and probably has it installed.

I'd like to document a "simple" one line command they can use to download my library's artifacts to their local ~/.m2/repository without requiring that they set up a pom.xml to do it.

I thought there was a way to do this, but I can't seem to find it after looking through the install:install-file and dependency plugin documentation. I tried things like:

mvn install:install-file -DrepositoryId=java.net -Durl=http://download.java.net/maven/2/ -Dfile=robo-guice-0.4-20091121.174618-1.jar -DpomFile=robo-guice-0.4-20091121.174618-1.pom -DgroupId=robo-guice -DartifactId=robo-guice -Dversion=0.4-SNAPSHOT -Dpackaging=jar

but I think I'm barking up the wrong tree since it appears that the install plugin is used to copy locally built files into the local repository, rather than download remote artifacts into the local repository.

This is the artifact I'd like to install: http://download.java.net/maven/2/robo-guice/robo-guice/0.4-SNAPSHOT/

Is this possible using maven?

asked Nov 21 '09 at 19:34
Image (Asset 2/5) alt=
up vote 103 down vote accepted

Since version 2.1 of the Maven Dependency Plugin, there is a dependency:get goal for this purpose. To make sure you are using the right version of the plugin, you'll need to use the "fully qualified name":

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
    -DrepoUrl=http://download.java.net/maven/2/ \
answered Nov 21 '09 at 21:14
Image (Asset 3/5) alt=
Pascal Thivent
Extra helpful for showing how to get the dependency plugin itself installed. – Sergio Acosta Apr 18 '10 at 6:49
Pascal, can you tell me how to define user+password to reach the repository with? The trick with user:password@repourl did not work. – Gábor Lipták Dec 2 '10 at 8:22
2 upvote
the goal is nice, but how can I define the target directory where I want the file to be copyed to? (and file name) – domi Jun 16 '11 at 8:44
6 upvote
@domi (belated answer for posterity): use "-Ddest=path/to/my.jar"; otherwise, it is just copied to your local ~/.m2/repository (makes it look like nothing happened). See maven.apache.org/plugins/maven-dependency-plugin/… =example=> mvn org.apache.maven.plugins:maven-dependency-plugin:2.5.1:get -DremoteRepositories=repo.maven.apache.org -Dartifact=org.apache.ant:ant:1.8.1 -Ddest=ant-1.8.1.jar (result: ant-1.8.1.jar in current directory) – michael_n Sep 10 '12 at 7:30
1 upvote
Thanks! While, in the doc link you posted, there is Deprecated. Use remoteRepositories for repoUrl. Please update the answer maybe:) – Weekend Oct 16 '15 at 4:13

Give them a trivial pom with these jars listed as dependencies and instructions to run:

mvn dependency:go-offline

This will pull the dependencies to the local repo.

A more direct solution is dependency:get, but it's a lot of arguments to type:

mvn dependency:get -DrepoUrl=something -Dartifact=group:artifact:version
answered Nov 21 '09 at 19:47
Image (Asset 4/5) alt=
Good idea, although a command line they could copy-paste would be easier – emmby Nov 21 '09 at 19:55
If I could think of one I'd post it. I don't know of any plugin that does quite what's called for. I know how to write one ... – bmargulies Nov 21 '09 at 20:39
The get mojo actually expects -DrepoUrl to be present, not -DrepositoryUrl. Regarding the arguments to type, there is no magic, you need to provide these informations in a way or the other. – Pascal Thivent Nov 22 '09 at 18:44
In my first scheme, the end user types only three characters: mvn. All the other typing is done by the op. – bmargulies Nov 22 '09 at 20:34

As of version 2.4 of the Maven Dependency Plugin, you can also define a target destination for the artifact by using the -Ddest flag. It should point to a filename (not a directory) for the destination artifact. See the parameter page for additional parameters that can be used

mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get \
    -DremoteRepositories=http://download.java.net/maven/2 \
    -Dartifact=robo-guice:robo-guice:0.4-SNAPSHOT \
answered Mar 27 '12 at 15:58
Image (Asset 5/5) alt=
Eric B.
Thanks! -Ddest is marked as deprecated. Is there a new solution new? – Dimath Mar 21 at 16:17

Your Answer


6 years ago


87437 times


3 years ago

Featured on Meta

Hot Network Questions

Technology Life / Arts Culture / Recreation Science Other
  1. Stack Overflow
  2. Server Fault
  3. Super User
  4. Web Applications
  5. Ask Ubuntu
  6. Webmasters
  7. Game Development
  8. TeX - LaTeX
  1. Software Engineering
  2. Unix & Linux
  3. Ask Different (Apple)
  4. WordPress Development
  5. Geographic Information Systems
  6. Electrical Engineering
  7. Android Enthusiasts
  8. Information Security
  1. Database Administrators
  2. Drupal Answers
  3. SharePoint
  4. User Experience
  5. Mathematica
  6. Salesforce
  7. ExpressionEngine® Answers
  8. Cryptography
  1. Code Review
  2. Magento
  3. Signal Processing
  4. Raspberry Pi
  5. Programming Puzzles & Code Golf
  6. more (7)
  1. Photography
  2. Science Fiction & Fantasy
  3. Graphic Design
  4. Movies & TV
  5. Music: Practice & Theory
  6. Seasoned Advice (cooking)
  7. Home Improvement
  8. Personal Finance & Money
  1. Academia
  2. more (8)
  1. English Language & Usage
  2. Skeptics
  3. Mi Yodeya (Judaism)
  4. Travel
  5. Christianity
  6. English Language Learners
  7. Japanese Language
  8. Arqade (gaming)
  1. Bicycles
  2. Role-playing Games
  3. Anime & Manga
  4. Motor Vehicle Maintenance & Repair
  5. more (17)
  1. MathOverflow
  2. Mathematics
  3. Cross Validated (stats)
  4. Theoretical Computer Science
  5. Physics
  6. Chemistry
  7. Biology
  8. Computer Science
  1. Philosophy
  2. more (3)
  1. Meta Stack Exchange
  2. Stack Apps
  3. Area 51
  4. Stack Overflow Talent
site design / logo © 2016 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0 with attribution required
rev 2016.11.3.4166