How to simply download a JAR using Maven?

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


Solution 1:

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

mvn dependency:get -DremoteRepositories=http://repo1.maven.org/maven2/ \
                   -DgroupId=junit -DartifactId=junit -Dversion=4.8.2 \
                   -Dtransitive=false

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.

Reference:

  • dependency:get

Solution 2:

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

Solution 3:

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:

<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
    <version>2.4.7</version>
</dependency>

Goto http://search.maven.org 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