Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download single/latest asset(JAR) from Nexus3

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?

enter image description here

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
}
like image 721
John Seen Avatar asked Feb 14 '18 21:02

John Seen


People also ask

How do I download a jar from Nexus repo?

create a maven project and add the jar (I want to download) to POM as dependency. using command mvn compile to the new maven project. maven will download the target jar and its dependencies to local repository. create a shell script to cope the jar and its dependencies to specific folder from local repository.

How do I get files from Nexus repository?

Go to Views/Repositories -> Repositories. Select the Maven Central repository and click on the Configuration tab. Set “Download Remote Indexes” to true and click on Save. Nexus will then download the repository index from the remote repository.

What is Nexus repository?

Nexus Repository OSS is an open source repository that supports many artifact formats, including Docker, Java™, and npm. With the Nexus tool integration, pipelines in your toolchain can publish and retrieve versioned apps and their dependencies by using central repositories that are accessible from other environments.


1 Answers

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
like image 177
VonC Avatar answered Sep 22 '22 05:09

VonC