Sonatype Nexus 3 - get latest snapshot

前端 未结 10 1502
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 06:28

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

10条回答
  •  太阳男子
    2020-12-31 07:03

    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
    

提交回复
热议问题