Search code examples
mavennexussonatype

Sonatype Nexus endpoint for artifact's version number


is there an endpoint in Nexus to get the artifact’s latest version ​number (pom’s version)?

If the artifact’s latest version in Nexus is 0.0.8-SNAPSHOT, the endpoint would return 0.0.8-SNAPSHOT.


Solution

  • You can use the following Nexus resolve REST API to obtain an XML document containing details about the POM, including the version:

    http://nexus/service/local/artifact/maven/resolve?g=groupId&a=artifactId&v=LATEST&r=snapshots&p=pom
    

    You'd then need to parse the text in the baseVersion element, e.g.

    <artifact-resolution>
      <data>
        ...
        <groupId>groupId</groupId>
        <artifactId>artifactId</artifactId>
        <version>1.0-20160000.100000-1</version>
        <baseVersion>1.0-SNAPSHOT</baseVersion>
        <extension>pom</extension>
        <snapshot>true</snapshot>
        ...
      </data>
    </artifact-resolution>
    

    Reference:

    https://repository.sonatype.org/nexus-restlet1x-plugin/default/docs/path__artifact_maven_resolve.html