Is there a way to download dependencies from a pom.xml file to a specified folder in java? I'm able to run maven command from java and I got download messages, but I don't know where maven stores these libraries? How can I download these dependencies to a specific folder?
Drop to a terminal in your project folder (where your pom. xml is located). Maven Dependency Plugin will download dependencies (for example, JAR files) into the folder target/dependency .
The Local Repository Maven's local repository is a directory on the local machine that stores all the project artifacts. When we execute a Maven build, Maven automatically downloads all the dependency jars into the local repository. Usually, this directory is named . m2.
Force maven to fetch dependencies from the remote repository while building the project. We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository.
Take a look at maven's dependency plugin, specifically the copy-dependencies
goal. The usage section describes how to do exactly what you want.
To do it from the command line just do:
$ mvn dependency:copy-dependencies -DoutputDirectory=OUTPUT_DIR
Add this to exclude the transitive or inner dependencies:
-DexcludeTransitive=true
As explained here, you can use maven-dependency-plugin:get for this.
For example, if you want to download org.apache.hive:hive-common:2.1.1
in your local folder, execute this:
mvn dependency:get -Ddest=./ -Dartifact=org.apache.hive:hive-common:2.1.1
If you want to download the latest 3.0.0-SNAPSHOT:tar.gz
version of com.orientechnologies:orientdb-community-gremlin
from https://oss.sonatype.org/content/repositories/snapshots
snapshots repository, execute this:
mvn dependency:get -Ddest=./ -DremoteRepositories=sonatype-nexus-snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dartifact=com.orientechnologies:orientdb-community-gremlin:3.0.0-SNAPSHOT:tar.gz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With