How do I find the latest version of an artifact from a maven repository

Pablojim picture Pablojim · Jul 29, 2009 · Viewed 18.8k times · Source

As part of an automated deployment I need a script to download the latest version of an artifact from our internal repository.

Ideally this script will be with ant or a unix shell script.

So for example:

I have myArtifact.war and it has versions 1.0 , 1.1 and 2.0 - I need the script given the correct group id and artifact id to retrieve version 2.0 from our maven repository (currently using artifactory).

Is there any easy way to do this?

Answer

Michael Tamm picture Michael Tamm · May 16, 2012

You can use the Maven Dependency Plugin goal get together with LATEST as version for your artifact:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get
    -DremoteRepositories=<URL_to_your_maven_repo>
    -Dartifact=<group_id>:<artifact_id>:LATEST
    -Dpackaging=jar
    -Ddest=<target_dir>/<artifact_name>.jar