48

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. :)

3
  • 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
    Commented Sep 26, 2011 at 18:31
  • that command did indeed download the the JARs, but it completely failed to setup the .project files
    – Albert
    Commented Sep 29, 2011 at 17:44
  • 1
    Possible duplicate of Maven: Command to update repository after adding dependency to POM
    – Vadzim
    Commented Feb 14, 2017 at 12:21

5 Answers 5

103

You can try this command:

mvn dependency:resolve

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

mvn install
5
  • 30
    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
    Commented Sep 26, 2011 at 18:39
  • 8
    "install" does try to compile it but "dependency:resolve" seemed to have worked. thanks!
    – Albert
    Commented Sep 26, 2011 at 20:16
  • If it says resolution will not be reattempted until the update interval of <some artifact> has elapsed or updates are forced then add -U in the args.
    – Peter
    Commented Dec 10, 2018 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
    Commented Feb 20, 2020 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
    Commented Jun 6, 2020 at 13:57
6

Try

mvn install dependency:copy-dependencies

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

1
  • Thank you! This is exactly what I was looking for!
    – rjcarr
    Commented Oct 20, 2020 at 18:51
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.

1
  • 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
    Commented Mar 31, 2021 at 14:47
0

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

0

Additionally to some other correct answers, it should be enough to invoke

mvn  dependency:copy-dependencies

you can the adjust the way, the download should be done, add

    <build>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <configuration>
                    <excludeTransitive>true</excludeTransitive>
                </configuration>
            </plugin>
        </plugins>

    </build>

to your pom with a configuration, that fits your needs. In the case here e.g. transitive downloads are not done. You will find your downloaded stuff in target/dependency

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.