402

I've added a new dependency to my POM.

Is there a simple command I can run to download this dependency to my repository?

1
  • For those looking on how to do this in a Spring Boot project: use mvnw to call the wrapper layer. The commands on this page work with it. Commented Jul 24, 2019 at 7:47

4 Answers 4

875

Per other answer, Maven will download the dependency as part of mvn compile, mvn install etc. By default it happens in the generate-sources phase of the default lifecycle - so invoking any phase from generate-sources onward will download dependencies.

If you want to only download dependencies without doing other activities such as compilation, then it's:

mvn dependency:resolve 

Or to download a single dependency:

mvn dependency:get -Dartifact=groupId:artifactId:version 

If you need to download from a specific repository, you can specify that with -DrepoUrl=...

Sign up to request clarification or add additional context in comments.

12 Comments

I get this error when I run that command: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get (default-cli) on project standalone-pom: The parameters 'repositoryUrl' for goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get are missing or invalid -> [Help 1]. Specifying -DrepositoryUrl=... doesn't work.
I think I've found the solution. The parameter should be "repoUrl" and not "repositoryUrl".
Doesn't solve the issue for me: the I run mvn package -o right after — I get error that plugins can not be downloaded. Running mvn dependency:resolve-plugins doesn't fully solve the issue either.
@Basti dependencies will be downloaded when running Maven lifecycle phases such as maven compile so for most people, that's all you need. But sometimes people want to download dependencies for whatever reason, without also invoking any other activities bound to any lifecycle stages. And that's what this question is for. In other words, if you're just using Maven normally, you don't need this question/answer.
I updated the answer to first point out that it happens anyway in most lifecycle phases. When I first wrote the answer, it was below the other answer that explained this.
|
257

mvn install (or mvn package) will always work.

You can use mvn compile to download compile time dependencies or mvn test for compile time and test dependencies but I prefer something that always works.

7 Comments

Thanks, I also discovered that adding it to the pom in STS will automatically download it for you.
@Andrew Spencer's reply is more accurate - mvn dependency:xxx deal with dependencies only and don't do any additional stuff - and that what the question was about.
At times, 'mvn package' may not update dependencies. Has happened to me more than once.One needs to run 'mvn dependency:resolve' in such cases
@BinitaBharati, you can add a -U to the Maven command line to force dependency downloads. This is useful if Maven doesn't download an updated dependency because of a cache timeout.
@Kishan Ask a new question. Show the layout of your project (especially where the import happens) and whether you use a multi-module build.
|
13

I know it is an old question now, but for users who are using Maven plugin with Eclipse under Windows, you have two options:

  1. If you got Maven installed as a standalone application:

    You can use the following command in the CMD under your project path:

    mvn eclipse:eclipse 

    It will update your repository with all the missing jars, according to your dependencies in your pom.xml file.

  2. If you haven't got Maven installed as a standalone application you can follow these steps on your eclipse:

    Right click on the project ->Run As -- >Run configurations.

    Then select mavenBuild.

    Then click new button to create a configuration of the selected type .Click on Browse workspace then select your project and in goals specify eclipse:eclipse

You can refer to how to run the command mvn eclipse:eclipse for further details.

6 Comments

Running eclipse:eclipse after dependency:resolve helped me see downloaded jars in eclipse, thanks!
While this answer will help the poor folk stuck with Eclipse, I strongly recommend that anyone using Eclipse find a better alternative. Especially if you're going to be using Maven. Netbeans and IntelliJ are light years ahead.
@64BitBob Assuming that Netbeans and IntelliJ are better than eclipse, we should always give a solution for those who use it. :)
I see that the plugin is not available anymore in marketplace but yes it works in Eclipse 2020 without downloading anything. I wonder if mvn eclipse:eclipse is the command sent by eclipse itself when we rightclick->Maven->Update Project...
@Paolo In my opinion they have automatically added the plugin in new versions of Eclipse, and yes I think it's the same command behind the "Update project" option.
|
-1

Pay attention to your dependency scope I was having the issue where when I invoke clean compile via Intellij, the pom would get downloaded, but the jar would not. There was a xxx.jar.lastUpdated file created. Then realized that the dependency scope was test, but I was triggering the compile. I deleted the repos, and triggered the mvn test, and issue was resolved.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.