How do you peg versions of Maven artifacts in the Nexus repository manager?

java, maven, nexus

Solution

When a snapshot is deployed to a repository server each new deployment is actually deployed as a time stamped version with an iterator number appended. If you want to use a specific version you just use the timestamp version of the snapshot rather than -SNAPSHOT.

E.g. look at https://repository.apache.org/content/groups/snapshots/org/apache/maven/artifact/maven-artifact/3.0-alpha-2-SNAPSHOT/

You could use this artifact as

<groupId>org.apache.maven.artifact</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.0-alpha-2-SNAPSHOT</version>

which would change it each time a new snapshot is deployed or you could use

<groupId>org.apache.maven.artifact</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.0-alpha-2-20090214.020928-1</version>

which would stay the same. Keep however in mind that a snapshot repository is NOT static by nature and these artifacts could potentially disappear completely. Only do that if you are using an internal repository server that you can control and therefore ensure that those snapshots don't disappear on you.

Another way to do it is to actually cut a release and use that..

Problem

I'm building against various Lucene and Solr Maven artifacts from Apache's Maven repository hosted in the Nexus repository manager. The artifacts are version `4.0-SNAPSHOT` and get updated daily, with older artifacts being deleted regularly. I was wondering how to peg the artifacts to a specific date, so whenever a Maven client would ask for `solr-core 4.0-SNAPSHOT`, it would get the same version even if there was a newer one upstream. I would also like to know how to explicitly update to the latest `4.0-SNAPSHOT`, but still keep all previous versions that were downloaded. Specifically, the "Apache Snapshots" repository is the default one that comes setup when you install Nexus.

Original source