How do I download JAR during a build in Maven script?


Maven does not work like that. Here’s the closest you’ll get to my knowledge:

mvn dependency:get -DremoteRepositories= 
                   -DgroupId=junit -DartifactId=junit -Dversion=4.8.2 

Note that all parameters except transitive are required.
Also note that Maven will download the jar to your local repository, and there’s no sensible way (that I know of) to copy it to a local directory.



Or since 3.1, simply as
mvn dependency:get -Dartifact=org.springframework:spring-instrument:3.2.3.RELEASE


Note: This answer is for downloading the jars directly from maven without any scripts [That is how Google directed me here]

Assuming mvn dependency is like this:


Goto and search for g:"com.zaxxer" AND a:"HikariCP" AND v:"2.4.7" (simply searching for HikariCP also works. You may need to select the appropriate GroupId and Version from the results)

In the Search Results -> Download column, you should see jar javadoc.jar sources.jar available for direct download


You can download Jar package to specific directory.

mvn dependency:get -Dartifact=org.riversun:random-forest-codegen:1.0.0 -Ddest=./


You can use:

mvn dependency:copy -Dartifact=<group>:<artifact-name>:<version> -DoutputDirectory=/tmp/my_custom_dir

(Replace <values> with the ones of your case)

That’s the full documentation of the goal:

Note: the other “dependecy:get” way of doing this has been deprecated.

See How to use Maven pom to download jar files only. This worked really nicely for me.

My use case was that I wanted to download some of the dependency jars to deploy to a QA server, and was doing it manually (outside of the Maven build). I’m not sure exactly what your use case is.

Normally you don’t use Maven for “just downloading”, but for your build process. So normally, you do the following steps:

  1. Define a new project by defining the archetype of your project and some needed properties.
  2. Define as a dependency the library you want to use.
  3. Run Maven with mvn compile

As a side effect, you will have downloaded the library to your local Maven repository. There are a lot of plugins to do something with dependencies, so have eg a look at the Maven Dependency plugin.


You can setup a pom.xml to define your dependencies (the jars you want to copy). Then use the dependency: copy-dependencies goal to copy the jars to the desired location.


This is what I do (2022 answer), go to, search for your .jar and click on here:
enter image description here

It’s possible to download a JAR from a Gitlab Maven private repository. The URL is appearing when running some Maven command so it’s a bit hacky but it’s working for me.

Like this:



  • GITLAB_PRIVATE_TOKEN is a Gitlab Token with right “api” (atm the others are not enough)
    • GITLAB_PROJECT_ID eg 1462237
    • MAVEN_PACKAGE_NAME eg com/bar/foo
    • MAVEN_VERSION eg 0.0.1
    • JAR_FILE eg foo-0.0.1.jar

Use the below code snip

result = subprocess.check_output('mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get 
                                     -DoutputDirectory=%s' % (group_id,
                                                              des_path), shell=True)"success download jar: %s" % each_version)
except Exception as e:
    logger.error("Error in download jar : %s" % str(e))

All the jars are available directly in the maven central repository. You don’t have to use “maven” if all you want is the jar.

If the pom dependency is


You can download it from the corresponding directory structure by replacing the dots with forward slashses on the group id, artifact id, and version. I would navigate to the final folder to get the exact link of the jar.

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