We\'ve just upgraded out nexus installation to the latest release (3.x). Is there any way to get the latest version of a given snapshot artifact? Nexus 2 had a nice API whic
Nexus 2 had a nice API which is not supported anymore.
It sounds like you are referring to these:
/service/local/artifact/maven/content
/service/local/artifact/maven/redirect
If you're asking to find the latest x.y.z-SNAPSHOT version where the x, y, z are guessed - Nexus never had this functionality (it worked only for plugins).
This is simply untrue - see the following article which shows clearly you can specify LATEST, RELEASE or SNAPSHOT base versions.
https://support.sonatype.com/hc/en-us/articles/213465488-How-can-I-retrieve-a-snapshot-if-I-don-t-know-the-exact-filename-
It's possible but not in a 1-liner.
Yes - unless you have a tool handy such as artifact-resolver which does uses a one line command to fetch an artifact.
It's possible but not in a 1-liner. You need to fetch the maven-metadata.xml for each snapshot artifact you're after (note that multi-module projects have different timestamps for each module including the parent).
We use xlstproc to extract the relevant variables so we are still able to run from the command line without heavyweight tools like maven or ivy to do the resolution.
If you ask for x.y.z-SNAPSHOT
then by default the latest x.y.z-timestamp
snapshot version will be downloaded. No need to do anything additional
If you're asking to find the latest x.y.z-SNAPSHOT
version where the x
, y
, z
are guessed - Nexus never had this functionality (it worked only for plugins). And I don't think there is any good use case for this. If this is needed, you're probably doing something wrong. You always should work with a specific version. Actually even for the 1st functionality I can't think of good use cases.
Using OSS 3.21.2-03 I have retrieved latest snapshot with following url on a zip extension file :
{nexus_host}/service/rest/v1/search/assets/download?sort=version&repository={repository_name}&group={group_id}&name={artifact-id}&maven.extension=zip
Bash one-liner using curl
, jq
, sort
and tail
:
NEXUS_URL=https://your-nexus.com
MAVEN_REPO=maven-snapshots
GROUP_ID=...
ARTIFACT_ID=...
VERSION=2.0.1-SNAPSHOT
FILE_EXTENSION=jar
download_url=$(curl -X GET "${NEXUS_URL}/service/rest/v1/search/assets?repository=${MAVEN_REPO}&maven.groupId=${GROUP_ID}&maven.artifactId=${ARTIFACT_ID}&maven.baseVersion=${VERSION}&maven.extension=${FILE_EXTENSION}" -H "accept: application/json" | jq -rc '.items | .[].downloadUrl' | sort | tail -n 1)
wget $download_url
What a joke re: Nexus 3 having no REST API.
I found a hack that alleviates my problem. Turns out that ansible has a nice maven_artifact module that is somehow able to figure out the latest snapshot. And you can run ansible locally. So it ends up looking like this:
ansible all -i localhost, -c local -m maven_artifact -a "repository_url=https://my-nexus/repository/maven-snapshots/ group_id=com.whatever artifact_id=my-artifact version=2.0-SNAPSHOT dest=./my-artifact.jar"