组内的Nexus REST API查询工件

Ser*_*nov 9 rest nexus

我有一个Nexus maven repo,我想利用REST API来查询我特定组中的工件列表.我偶然发现了这个文档,但它似乎非常简洁,我找不到我需要的东西.

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

我想要这样的东西

http://mydomain:8081/nexus/service/local/repositories/list?groupId=com.test.superproduct&repo=snapshots
Run Code Online (Sandbox Code Playgroud)

它会输出一个列表

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

更具体地说,我需要一个位于组中的工件版本列表,但我也可以从工件名称中提取版本.

Ser*_*nov 16

我发现我需要的是获取maven-metadata.xml`文件,该文件包含此工件可用的所有版本.例如,

https://oss.sonatype.org/service/local/repositories/snapshots/content/com/alibaba/rocketmq/rocketmq-all/maven-metadata.xml
Run Code Online (Sandbox Code Playgroud)

包含

<?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>
Run Code Online (Sandbox Code Playgroud)


kub*_*zyk 15

无需手动解析maven-metadata.xml.无需手动解析目录名称或文件名.

http://localhost/nexus/service/local/lucene/search?g=com.foo&a=foo-bar
Run Code Online (Sandbox Code Playgroud)

不仅返回<version>此版本的每个工件的每一个,而且作为奖励,获取驻留在此Nexus实例上的任何单个文件的唯一下载URL所需的所有标识符.下载URL所需的标识符是:<groupId>,<artifactId>(这两个你说你已经知道了), ,<version>,<repositoryId>(<extension><classifier>这是可选的,不确定的在我的例子):

...
<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>
Run Code Online (Sandbox Code Playgroud)

在解析lucene/search响应之后,一个好主意是通过repositoryId将其过滤为releases或者snapshots.

这个答案适用于Nexus 2.11.

  • 这太棒了!这解决了我一直想要解决的问题很长一段时间! (2认同)

nab*_*cos 5

通常,您希望使用为存储库维护的lucene索引来进行这样的查找.请参阅索引器插件的REST文档,您可以在此处搜索groupId和artifactId.