47

I would like to have Maven download the JARs listed in a pom.xml file. How do I do that? Currently, Maven wants to compile the project (and it fails). I don't care about compiling it because I'm compiling manually. I just want the JARS. Help?

Albert

ps: Background, I am compiling it manually because I can easily debug the project in Eclipse. I've manually downloaded a bunch of JAR files, but I suspect there's a JAR version mismatch as there's a mysterious error at runtime. I would do this checking manually, but there are hundreds of associated JAR files. Ideally, I want to download all the JAR files, point my Eclipse project to the newly download JARS, and get on with my life. :)

Albert
  • 523
  • 2
  • 5
  • 5
  • which maven command are you currently using? "mvn eclipse:eclipse -DdownloadSources" should normally just download jars to local repo and set up .project files with dependencies (NB: overwriting what's already there). – ivarni Sep 26 '11 at 18:31
  • that command did indeed download the the JARs, but it completely failed to setup the .project files – Albert Sep 29 '11 at 17:44
  • 1
    Possible duplicate of [Maven: Command to update repository after adding dependency to POM](http://stackoverflow.com/questions/8563960/maven-command-to-update-repository-after-adding-dependency-to-pom) – Vadzim Feb 14 '17 at 12:21

4 Answers4

100

You can try this command:

mvn dependency:resolve

Or just invoke the "install" life cycle as follows:

mvn install
Mr.Eddart
  • 10,050
  • 13
  • 49
  • 77
  • 28
    I am pretty sure "install" will attempt to compile (and run tests) and for a multi-module project it will abort on first error and not download any jars for the following modules. That's how it acts when I use it anyway. – ivarni Sep 26 '11 at 18:39
  • 7
    "install" does try to compile it but "dependency:resolve" seemed to have worked. thanks! – Albert Sep 26 '11 at 20:16
  • If it says `resolution will not be reattempted until the update interval of has elapsed or updates are forced` then add -U in the args. – Peter Dec 10 '18 at 12:18
  • I have done a quick test and it seems dependency:resolve prints out the dependencies, but it doesn't download them... – jplandrain Feb 20 '20 at 11:33
  • 1
    @jplandrain Maven 3.6.3 also downloads the artifacts if not yet available from the local repo. Just checked. After that it prints the dependencies – rmuller Jun 06 '20 at 13:57
5

Your best approach is to use m2eclipse and import your pom into eclipse. It will download and link all dependencies to your project, and as an added bonus, it will also download and associate their source and javadoc jars. It does not really matter if the project has hundreds or just few dependencies, it will work the same.

Sometimes, we want to do something quickly and be done with it, but it ends up taking longer than doing the right away especially when there hundreds of dependencies.

Pierre
  • 1,329
  • 2
  • 12
  • 21
  • While this is great advice, I think the OP just wanted to know how to download all the jars. Which would be: "mvn dependency:resolve" (to local maven repo) or "mvn dependency:copy-dependencies" (to target dir) – Chris Wolf Mar 31 '21 at 14:47
4

Try

mvn install dependency:copy-dependencies

You will see all the jars under 'target/dependency' folder

Rajeev
  • 41
  • 2
0

If you are using eclipse, I believe you can just right click on the project --> maven --> update project

schnarbies
  • 61
  • 5