Horace Williams

Manually download JAR to local Maven cache

Sometimes I need to install a JAR from a remote Maven server into my local ~/.m2 repository for testing or experimentation (i.e. in absence of an actual pom.xml / project.clj / build.sbt file).

It always takes longer to figure this out than I’d expect since mvn doesn’t have something as easy as Ruby or Python’s gem/pip install <package>.

It is supported though and you can do it with:

$ mvn -DgroupId=<GROUP> \
      -DartifactId=<PACKAGE> \
      -Dversion=<VERSION> \


$ mvn -DgroupId=org.locationtech.jts \
      -DartifactId=jts-core \
      -Dversion=1.15.0 \
# [Maven Output...]
$ find ~/.m2 -name "*jts-core*jar"
# /home/horace/.m2/repository/org/locationtech/jts/jts-core/1.15.0/jts-core-1.15.0.jar

To fetch one from an internal or private maven repo, you can use the additional setting remoteRepositories:

$ mvn -DremoteRepositories=<MAVEN URL> \
      -DgroupId=<GROUP> \
      -DartifactId=<PACKAGE> \
      -Dversion=<VERSION> \

Note that if you’re running Nexus, you may need the full url to your releases directory, e.g. http://maven.my.company.com/nexus/content/repositories/releases.