Nexus REST API query artifacts within a group
It came out that everything I needed is to fetch ˇmaven-metadata.xml` file that comprises all versions available for this artifact. For example,
https://oss.sonatype.org/service/local/repositories/snapshots/content/com/alibaba/rocketmq/rocketmq-all/maven-metadata.xml
contains
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>com.alibaba.rocketmq</groupId>
<artifactId>rocketmq-all</artifactId>
<versioning>
<latest>3.1.8-SNAPSHOT</latest>
<release></release>
<versions>
<version>3.0.2-open-SNAPSHOT</version>
<version>3.0.10-ALIYUN-SNAPSHOT</version>
<version>3.0.11-SNAPSHOT</version>
<version>3.1.8-SNAPSHOT</version>
</versions>
<lastUpdated>20140807060304</lastUpdated>
</versioning>
</metadata>
Usually you would want to use the lucene index maintained for the repositories for lookups like this. See the REST documentation for the indexer plugin, you can search for groupId and artifactId here.
No need to manually parse maven-metadata.xml. No need to manually parse directory names or file names.
http://localhost/nexus/service/local/lucene/search?g=com.foo&a=foo-bar
returns not only every <version>
, but as a bonus, for every artifact of this version, all the identifiers needed to obtain an unique download URL for any single file residing on this Nexus instance. The identifiers required for download URL are: <groupId>
, <artifactId>
(both of which you say you already know), <version>
, <repositoryId>
, <extension>
(and <classifier>
which is optional and undefined in my example):
...
<artifact>
<groupId>com.foo</groupId>
<artifactId>foo-bar</artifactId>
<version>2.8.1</version>
<latestSnapshot>2.8.5-SNAPSHOT</latestSnapshot>
<latestSnapshotRepositoryId>snapshots</latestSnapshotRepositoryId>
<latestRelease>2.8.3</latestRelease>
<latestReleaseRepositoryId>releases</latestReleaseRepositoryId>
<artifactHits>
<artifactHit>
<repositoryId>releases</repositoryId>
<artifactLinks>
<artifactLink>
<extension>pom</extension>
</artifactLink>
<artifactLink>
<extension>war</extension>
</artifactLink>
</artifactLinks>
</artifactHit>
</artifactHits>
</artifact>
<artifact>
<groupId>com.foo</groupId>
<artifactId>foo-bar</artifactId>
<version>2.8.0</version>
<latestSnapshot>2.8.5-SNAPSHOT</latestSnapshot>
<latestSnapshotRepositoryId>snapshots</latestSnapshotRepositoryId>
<latestRelease>2.8.3</latestRelease>
<latestReleaseRepositoryId>releases</latestReleaseRepositoryId>
<artifactHits>
<artifactHit>
<repositoryId>releases</repositoryId>
<artifactLinks>
<artifactLink>
<extension>pom</extension>
</artifactLink>
<artifactLink>
<extension>war</extension>
</artifactLink>
</artifactLinks>
</artifactHit>
</artifactHits>
</artifact>
After you parse lucene/search
response, a good idea would be to filter it by repositoryId being either releases
or snapshots
.
This answer is for Nexus 2.11.