I am trying to download the latest/newest asset(JAR) from my local Nexus repo. I am using Nexus Swagger UI. It has a GET method to download,
GET /beta/search/assets/download
The issue is..I have many assets in the repo, and it gives an error,
Search returned multiple assets, please refine search criteria to find a single asset
How do I refine my search & get the latest/newest JAR?
FYI.. currently, I have 20+ assets in the repo, below I am showing two of them..
{
"items": [
{
"downloadUrl": "http://localhost:8081/repository/snapshot/com/openshift/test/openshift-jenkins/0.0.1-SNAPSHOT/openshift-jenkins-0.0.1-20180214.211251-17.jar",
"path": "com/openshift/test/openshift-jenkins/0.0.1-SNAPSHOT/openshift-jenkins-0.0.1-20180214.211251-17.jar",
"id": "c25hcHNob3Q6ZTAxODhlZDA3MjhmYTY4ZmIwOGZkYzAyYTliZTQ4Zjg",
"repository": "snapshot",
"format": "maven2",
"checksum": {
"sha1": "53cdfcf964d0edd5fc6fdefa457e700eff47a1ca",
"md5": "d0c82971b82957728d0b4c858150d56c"
}
},
{
"downloadUrl": "http://localhost:8081/repository/snapshot/com/openshift/test/openshift-jenkins/0.0.1-SNAPSHOT/openshift-jenkins-0.0.1-20180214.210246-15.jar",
"path": "com/openshift/test/openshift-jenkins/0.0.1-SNAPSHOT/openshift-jenkins-0.0.1-20180214.210246-15.jar",
"id": "c25hcHNob3Q6MjEwMzFkZmFmNDVlNWI1ODgwZTUwYjE5M2Y5NGVkNjk",
"repository": "snapshot",
"format": "maven2",
"checksum": {
"sha1": "b041f4b1e6bcb81366a72635f6c576ae46a83ec8",
"md5": "af970e3e66c9cd20ff66f1074da04c21"
}
}
],
"continuationToken": null
}
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'.
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:
assets/download
sort=version
modifier