I would like to provide a simple URL that will always return the latest version of a snapshot version of an artifact. By simple I mean that the URL doesn't change, or require the user to browse the directory and examine timestamps.
4 Answers
Please note
- this answer relates to Nexus 2.X
- There is a noticeable performance impact of using the restlet API to download large artifacts, see: https://community.sonatype.com/t/slow-artefacts-download-performance-with-oss-2-x/2280
The core Nexus "redirect" REST API can be used to retrieve any version of an artifact from a nominated repository:
For example:
The v parameter can be a value like 1.0-SNAPSHOT, in which case Maven will return the latest time-stamped snapshot held in the repository. Similiarily the special value "LATEST" should do the same provided a more recent released version is not present.
-
1Make sure to use the repository ID and not the repository name for the "r" parameter– evandorMar 7, 2012 at 14:10
-
1This is a working URL of the documentation @Mark O'Connor , you can update the answer so the readers dont have to go through the comments. Oct 22, 2013 at 8:37
-
2
-
1@ThiagoArrais This REST API is not yet available in Nexus 3. See Nexus Jira.– ᴠɪɴᴄᴇɴᴛMar 8, 2017 at 16:00
-
1Something that should be added is that there is a noticeable performance impact of using the restlet API to download large artifacts, see: community.sonatype.com/t/… Sep 5, 2019 at 11:58
on my nexus machine all results for :
are like this: *-1.2.3-20131204.143026-1.zip
so I can't access it directly because I need to provide more details that are dynamic.
The example with "...redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST" is working if I open in browser but not when I what to install it from some linux machine using:
/usr/share/elasticsearch/bin/plugin --url "http://localhost:8081/nexus/service/local/artifact/maven/redirect?r=snapshots&g=com.comapny.application&a=elasticsearch-river-mongodb&v=1.2.3-SNAPSHOT&p=zip" --install river-mongodb
So my temporary solution is using wget :
wget -O /tmp/elasticsearch-river-mongodb.zip "http://nexushost.domain/nexus/service/local/artifact/maven/redirect?r=snapshots&g=com.comapny.application&a=elasticsearch-river-mongodb&v=1.2.3-SNAPSHOT&p=zip"
then install LATEST version from local file.
If you're looking for the latest version of a snapshot, just asking for say, "1.0-SNAPSHOT" will return the latest version of that artifact's snapshot.
If you're looking for "latest version" however, the "v=LATEST" syntax will work, but keep in mind that this keyword can return the latest version of that snapshot you're looking for, or the release that just completed, or that OTHER branch of that same artifact that is a version ahead and still at "-SNAPSHOT".
If you're looking for the absolute latest then yeah, use the "v=LATEST". If you're looking for the latest release, you can also ask for "v=RELEASE". If you have a grouping of repos, you can reference both snapshot repos and release repositories by adding to the url something like:
"...v=RELEASE&r=public"
That should search across all your "grouped" repos.
Every repository has its own url (you can see it in the Repository browser). If you open it, you can browse through the group and artifact ids to your artifact. That's your url, for example like this: http://nexushost.domain/content/repositories/snapshots/com/example/group/artifact/1.2.3-SNAPSHOT/1.2.3-SNAPSHOT.jar
-
-
@chad. That's what -SNAPSHOT does. Think of it as a symlink to a latest timestamped version. Feb 14, 2012 at 18:30
-
1That definitely does not work for me. I wouldn't have expected that the direct http browsing of the repository would give me that layer of metadata inspection of resolution. Is it possible that I need to configure the repository in some way for this . . .– chadFeb 14, 2012 at 18:35
-
1This only works with Maven 2 where you can upload snapshot artifacts without timestamps. In Maven 3 this behavior was removed. Jul 23, 2014 at 8:24
-
1Yes, in that case you can use an appropriate Nexus URL: nexushost.domain/service/local/artifact/maven/…– dunniJul 23, 2014 at 11:36