Download single/latest asset(JAR) from Nexus3
Instead of using a search, you might using an artifact redirtect (with curl -L being able to follow the redirection): /artifact/maven/redirect
curl -L "http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST" -o log4j.jar
However, it might not be available for Nexus 3 yet.
In that case, you need to download and parse first the maven-metadata.xml
.
You can extract from there the latest tag.
Sice Feb. 2018, NEXUS-12469 asks the same question, and references NEXUS-14407: REST Search & Download by 'Latest', released in 3.16, Q4 2019.
Extend the search & download service so that users can sort the search results by 'latest version'.
Examples:
http://localhost:8081/service/rest/v1/search/assets/download?repository=maven-central&group=junit&name=junit&sort=version&prerelease=false
curl -L -o myartifact.tar.gz -u xxx:xxx "http://localhost:8080/service/rest/v1/search/assets/download?sort=version&direction=desc&repository=maven-snapshots&maven.groupId=bla.bla.bla&maven.artifactId=bla-bla&maven.extension=tar.gz
So a combination of:
- API endpoint
assets/download
sort=version
modifier
Using the REST API in v3 (3.17.0 to be exact) the following should work to get the latest version of any lib:
/service/rest/v1/search/assets/download?sort=version&maven.artifactId=artifactId&maven.groupId=groupId&maven.extension=jar