Using the Nexus rest API to get latest artifact version for given groupid/artifactId

后端 未结 6 1199
走了就别回头了
走了就别回头了 2020-11-27 14:53

I am trying to use the nexus REST api to get the latest version of a maven artifact. I am able to browse to the specific version I am looking for using http://repo.loc

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 15:31

    This answer has been copied from: https://stackoverflow.com/a/39485361/1450799

    I have Linux OS and I do not have access to REST API, so I used following commands to get the latest version of snapshots from Nexus:

    An example snapshots maven-metadata.xml from WSO2 repository:

    $ curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml"
    
    
      org.wso2.is
      wso2is
      
        5.3.0-SNAPSHOT
        
        
          5.1.0-SNAPSHOT
          5.2.0-SNAPSHOT
          5.3.0-SNAPSHOT
        
        20160914062755
      
    
    

    Extracting from latest XML tag inside maven-metadata.xml:

    curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml" | \
    grep ".*" | \
    sed -e "s#\(.*\)\(\)\(.*\)\(\)\(.*\)#\3#g"
    

    Extracting from version XML tag inside maven-metadata.xml:

    curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml" | \
    grep ".*" | \
    sort --version-sort | uniq | tail -n1 | \
    sed -e "s#\(.*\)\(\)\(.*\)\(\)\(.*\)#\3#g"
    

    The result of both of the commands until today 14 Sep 2016 is:

    5.3.0-SNAPSHOT
    

提交回复
热议问题