Nexus REST API request artifacts within a group

I have a Nexus maven repository, and I would like to use the REST API to request a list of artifacts that lie in my specific group. I stumbled upon this documentation, but it seems very concise, and I cannot find there what I need.

https://oss.sonatype.org/nexus-restlet1x-plugin/default/docs/rest.html

I need something like this

http://mydomain:8081/nexus/service/local/repositories/list?groupId=com.test.superproduct&repo=snapshots 

And he will give me a list

  • product-1.0.0-SNAPSHOT
  • product-1.0.1-SNAPSHOT
  • product-1.0.2-SNAPSHOT .....

To be more specific, I need a list of versions of artifacts that lie in the group, but I can also extract versions from the names of artifacts.

+6
source share
3 answers

It turned out that all I need is to get the maven-metadata.xml` file, which contains all the versions available for this artifact. For instance,

 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> 
+14
source

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 for each <artifactHit> all other elements that uniquely identify everything that can be downloaded from this Nexus URL, namely: <repositoryId> and <extension> (and <classifier> are undefined here):

 ... <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> 

So, after you analyze the lucene / search answer yourself, you can filter it using repositoryId. This answer is for Nexus 2.11.

+9
source

Usually you need to use the lucene index, which is supported for repositories for such queries. See the REST documentation for the indexer plugin , you can search here for groupId and artifactId.

+5
source

Source: https://habr.com/ru/post/972834/


All Articles