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
I've put together a groovy script that can be uploaded to Nexus which solves this particular issue with a POST request.
You can find the script and some usage instructions here: https://github.com/rbjorklin/resolve-latest-nexus-artifact
Asof April 2019 there IS a REST API in Sonatype Nexus 3 for accessing the latest artefact
Documentation is here
http://community.sonatype.com/t/nxrm-3-16-rest-search-and-filtering-enhancements/1586
Use this endpoint /service/rest/v1/search/assets/download
with repository
, group
and name
arguments. Sorting by version
will get you the latest timestamped snapshot.
https://nexus.blahblah.com/service/rest/v1/search/assets/download?repository=maven-snapshots&group=com.my.company&name=myArtefact&sort=version&direction=desc
recently we faced the same problem with nexus version 3.12.1-01, so there is definitely not rest api to get latest snapshot directly
we were able to solve the problem using python one liner
JSON_RESPONSE=$(curl -u un:pw -X GET "http://nexus-host/nexus/service/rest/beta/search/assets?maven.groupId=sample.group.id&maven.artifactId=sample&maven.extension=jar" -H "accept: application/json")
echo $JSON_RESPONSE | python -c 'import sys, json; lines = json.load(sys.stdin)["items"]; sortedlines = sorted(lines, key=lambda k: k["downloadUrl"], reverse=True); print(sortedlines[0]["downloadUrl"])'
hope it helps
You can download with curl
curl -L --header 'Accept: application/json' "https://${NEXUS_URL}/service/rest/beta/search/assets/download?repository=${NEXUS_REPO_NAME}&maven.groupId=${MVN_GROUP_ID}&maven.artifactId=${MVN_ARTIFACT_ID}&maven.baseVersion=${APP_VERSION}&maven.extension=${MVN_EXTENSION}"