May 22, 2014

Downloading a JAR's Dependencies

Ever find a jar that has it’s dependencies declared in a pom, but you don’t use maven?

I do all the time… because I don’t ever use maven!

So, here’s the deal:

  1. create a pom that looks something like this:

     <?xml version="1.0"?>
     <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
         <groupId>com.doesnt.matter</groupId>
         <artifactId>AlsoDoesntMatter</artifactId>
         <version>1.0-SNAPSHOT</version>
         <name>Simple POM to download some dependencies</name>
         <url>http://jonfuller.co</url>
         <dependencies>
             <dependency>
                 <groupId>com.netflix.rxjava</groupId>
                 <artifactId>rxjava-core</artifactId>
                 <version>0.18.3</version>
                 <scope/>
             </dependency>
         </dependencies>
     </project>
    

    The example above downloads the dependencies for Netflix’s rxjava-core (version 0.18.3) jar.

    Note: Figure out your dependeny’s actual groupId, artifactId, and version numbers are by checking out maven central

  2. execute this at your terminal:

     mvn -f example-pom.xml dependency:copy-dependencies
    

    Need maven? brew install maven, if you’re on OS X.

  3. wait while maven downloads the Internet.

  4. bask in the glory of your new pile of jars. (located at target/dependency)

For me, I was really wanting to download the dependencies for retrofit. I’ve dropped the above and an example for retrofit into a gist for your viewing pleasure: