Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download jars from Maven Central without writing any pom.xml [duplicate]

Tags:

java

maven-2

I would like something like the following.

I want just an utility that is able to download jars and their dependencies from the Maven Repository without imposing no constraints on how my project should be built.

I would like something like this:

download-jar --dest=lib/ 'commons-io:commons-io:jar:1.4'

It should be able to download also the dependencies.

Update:

I wouldn't know about a pom.xml should be structured.

The only task I need to be accomplished is the download of the jars, I would like have a tool that could accomplish this task that doesn't bother me with superflous information.

There is something like that?

like image 729
Andrea Francia Avatar asked Aug 30 '10 14:08

Andrea Francia


4 Answers

If you want to download maven dependencies into your lib directory use the dependency plugin with the copy-dependencies function.

mvn -DoutputDirectory=./lib -DincludeArtifactIds=commons-logging,commons-io dependency:copy-dependencies 

Without the -DincludeArtifactIds part you'll download every dependency.

If you want to download a an artifact without having a specific project *see below** :

mvn -DgroupId=commons-io -DartifactId=commons-io -Dversion=1.4 dependency:get

Resources :

  • maven.apache.org - dependency:copy-dependencies
  • force Maven2 to copy dependencies into target/lib
  • maven.apache.org - dependency:get *see below**

On the same topic :

  • Aggregate Dependencies in a Multi-Module Maven Project
  • Set plugin's property on the command line in maven 2
  • A simple command line to download a remote maven2 artifact to the local repository? *see below**

Interesting comments :

  • *@Pascal Thivent :

    No need to setup a POM, no need to develop your own tool, use mvn dependency:get. That's the right answer to this question.

like image 64
Colin Hebert Avatar answered Oct 12 '22 23:10

Colin Hebert


I also had to specify -DrepoUrl, after getting the error message:

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]

So here is the command I used:

mvn -DgroupId=edu.umd -DartifactId=cloud9 -Dversion=1.3.5 \
  -DrepoUrl="http://repo1.maven.org/maven2" dependency:get

Furthemore, -Ddest=~ didn't work. It always insisted on installing the jar to ~/.m2/repository.

like image 42
chbrown Avatar answered Oct 12 '22 23:10

chbrown


Maven3 uses dependency plugin v2.1 by default:

$ mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ \
   -DgroupId=commons-io -DartifactId=commons-io -Dversion=1.4

With Maven2 is still necessary to write the canonical name:

$ mvn2 org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
   -DrepoUrl=http://download.java.net/maven/2/ \
   -DgroupId=commons-io -DartifactId=commons-io -Dversion=1.4

Use parameter artifact to set the name of the artifact as group:artifact:version:

$ mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ \
   -Dartifact=commons-io:commons-io:1.4

Use LATEST to download the latest version of the artifact:

$ mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ \
   -Dartifact=commons-io:commons-io:LATEST
like image 8
Diego Pino Avatar answered Oct 13 '22 01:10

Diego Pino


You should take a look at the maven dependency plugin, maybe ... and especially its go-offline mojo

like image 1
Riduidel Avatar answered Oct 12 '22 23:10

Riduidel