45

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.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
chad
  • 7,369
  • 6
  • 37
  • 56
  • 1
    I had exactly the same question. I'm writing scripts that download artifacts from Nexus and the dynamic URLs for snapshots where annoying. – Geert Schuring Jul 23 '14 at 08:27

4 Answers4

61

Please note

The core Nexus "redirect" REST API can be used to retrieve any version of an artifact from a nominated repository:

For example:

https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST

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.

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • 1
    Make sure to use the repository ID and not the repository name for the "r" parameter – evandor Mar 07 '12 at 14:10
  • Wish I could give you two upvotes! The only thing you omitted is a (working?) link to the REST API docs, which should be something like /nexus-core-documentation-plugin/core/docs/index.html. – Tomislav Nakic-Alfirevic Dec 14 '12 at 12:52
  • @TomislavNakic-Alfirevic Yeah, the link in my answer no longer works.... Sonatype change their site and server setup quite a bit... It's a terrible pity there is no master reference site for the REST API docs. As you've stated the rest doco is available from local instance. – Mark O'Connor Dec 16 '12 at 18:34
  • 1
    This is a working URL of the [documentation](https://maven.java.net/nexus-core-documentation-plugin/core/docs/rest.artifact.maven.redirect.html) @Mark O'Connor , you can update the answer so the readers dont have to go through the comments. – Sinisha Mihajlovski Oct 22 '13 at 08:37
  • It has a dark side: [Nexus: why you shouldn't use LATEST](http://somerepo.org/service/local/artifact/maven/redirect?r=central-proxy&g=groupId&a=artifactId&v=LATEST) – Ondra Žižka Jan 08 '15 at 01:41
  • This wasn't working for me for snapshots because of "Repository policy RELEASE". What did work for releases is https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy& ... and for snapshots, https://oss.sonatype.org/service/local/artifact/maven/redirect?r=snapshots& ... – Daniel Widdis Sep 20 '15 at 21:43
  • 2
    is this deprecated in Nexus 3 or is it my installation? – Thiago Arrais Feb 01 '17 at 18:50
  • 1
    @ThiagoArrais This REST API is not yet available in Nexus 3. See [Nexus Jira](https://issues.sonatype.org/browse/NEXUS-11891). – ᴠɪɴᴄᴇɴᴛ Mar 08 '17 at 16:00
  • Normally this works fine for me but I've just experienced an issue. I just released a version 2.0 to `releases` then started `2.1-SNAPSHOT`, the `resolve` and `redirect` API's are still both returning the 2.0 artifact with `v=LATEST`. when I use `v=2.1-SAPSHOT` I get the expected result. My params are `resolve?g=gid&a=artifactName&v=LATEST&r=snapshots&p=jar` where `gid` and `artifactName` are the references. – Brett Ryan May 15 '17 at 12:46
  • 1
    Something that should be added is that 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 – Joel Arnold Sep 05 '19 at 11:58
  • It seems that central-proxy does not support snapshots anymore: `Retrieval of /foo/3.3-SNAPSHOT/foo-3.3-SNAPSHOT-jar-with-dependencies.jar from M2Repository(id=central-proxy) is forbidden by repository policy RELEASE.` Any idea? – Martin Monperrus Mar 26 '20 at 12:28
3

on my nexus machine all results for :

http://nexushost.domain/nexus/content/repositories/snapshots/com/company/elasticsearch-river-mongodb/1.2.3-SNAPSHOT/

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.

matei.nick
  • 161
  • 1
  • 5
3

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.

EJC
  • 331
  • 2
  • 4
-1

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

dunni
  • 43,386
  • 10
  • 104
  • 99
  • We use timestamped snapshot versions, so it's not that simple. – chad Feb 14 '12 at 18:16
  • @chad. That's what -SNAPSHOT does. Think of it as a symlink to a latest timestamped version. – Alexander Pogrebnyak Feb 14 '12 at 18:30
  • 1
    That 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 . . . – chad Feb 14 '12 at 18:35
  • 1
    This only works with Maven 2 where you can upload snapshot artifacts without timestamps. In Maven 3 this behavior was removed. – Geert Schuring Jul 23 '14 at 08:24
  • 1
    Yes, in that case you can use an appropriate Nexus URL: https://nexushost.domain/service/local/artifact/maven/redirect?r=repositoryId&g=com.example.groupid&a=artifactId&v=1.0-SNAPSHOT&p=packaging – dunni Jul 23 '14 at 11:36