简体   繁体   English

OSS Nexus:如何使用REST API将最新版本作为文本检索

[英]OSS Nexus: how to use REST API to retrieve last version as a text

I'd like to retrieve the latest version name (as text) to be able to rename the artificats retrieved from Nexus which have timestamps. 我想检索最新的版本名称(作为文本),以便能够重命名从Nexus检索到的具有时间戳的艺术品。

What I do is create an archive of several archives containing in-house jar projects, dependencies, related scripts, ... But if the packaged jars are snapshots, the archives end up with timestamps when downloaded. 我所做的是创建包含内部jar项目,依赖项,相关脚本的几个档案的存档......但是如果打包的jar是快照,则存档在下载时会以时间戳结束。 Those timestamps replace the XXX-SNAPSHOT extension of the archive and I cannot make any automated script to perform some tasks like extracting the archive, renaming the directory, make some symbolic links, ... 这些时间戳取代了存档的XXX-SNAPSHOT扩展名,我无法使任何自动脚本执行某些任务,如提取存档,重命名目录,制作一些符号链接,......

I did not find anything related to this in the rest api documentation. 我没有在其余的api文档中找到与此相关的任何内容。 Is there a simple way to do this with the rest api or some kind of scripting? 有没有一个简单的方法来执行其余的api或某种脚本?

Thanks. 谢谢。

Edit: 编辑:

From the below answer I managed to retrieve the latest snapshot version using LATEST instead of the version name: 从下面的答案我设法使用LATEST而不是版本名称检索最新的快照版本:

Then using a script I can retrieve the base version. 然后使用脚本我可以检索基本版本。

#!/bin/bash
VERSION=`curl --silent "http://redmine.saic.int:8081/nexus/service/local/artifact/maven/resolve?r=snapshots&g=com.g2mobility&a=G2-Modem-Mgr&v=LATEST&c=executable&e=tar.gz" | sed -n 's|<baseVersion>\(.*\)</baseVersion>|\1|p'`

VERSION=`echo "$VERSION" | tr -d ' '`

echo "Version is $VERSION"

Thanks! 谢谢!

Nexus has the following REST API for describing how Maven modules are resolved: Nexus具有以下REST API,用于描述如何解析Maven模块:

Example

To obtain the details about the following artifact: 要获取有关以下工件的详细信息:

<groupId>org.cometd.jetty</groupId>
<artifactId>cometd-jetty-client</artifactId>
<version>1.0-SNAPSHOT</version>

Use the following REST API: 使用以下REST API:

https://oss.sonatype.org/service/local/artifact/maven/resolve?r=cometd-snapshots&g=org.cometd.jetty&a=cometd-jetty-client&v=1.0-SNAPSHOT&e=jar https://oss.sonatype.org/service/local/artifact/maven/resolve?r=cometd-snapshots&g=org.cometd.jetty&a=cometd-jetty-client&v=1.0-SNAPSHOT&e=jar

Returns the following report: 返回以下报告:

<artifact-resolution>
  <data>
    <presentLocally>true</presentLocally>
    <groupId>org.cometd.jetty</groupId>
    <artifactId>cometd-jetty-client</artifactId>
    <version>1.0-20090313.100344-2</version>
    <baseVersion>1.0-SNAPSHOT</baseVersion>
    <extension>jar</extension>
    <snapshot>true</snapshot>
    <snapshotBuildNumber>2</snapshotBuildNumber>
    <snapshotTimeStamp>1236938624000</snapshotTimeStamp>
    <sha1>0cbf7163f19bf4586e27632a1f742dd0c0e0036d</sha1>
    <repositoryPath>/org/cometd/jetty/cometd-jetty-client/1.0-SNAPSHOT/cometd-jetty-client-1.0-20090313.100344-2.jar</repositoryPath>
  </data>
</artifact-resolution>

This was an eariler deleted posting proposing an alternative way of assembling distributions from Maven repository content: 这是一个删除了漏洞的帖子,提出了一种从Maven存储库内容组装发行版的替代方法:

Ivy is an alternative dependency management client, which can be run from the command-line as follows: 常春藤是一种替代依赖管理客户机,它可从运行的命令行如下:

java -jar ivy.jar -settings ivysettings.xml -dependency org.cometd.jetty cometd-jetty-client 1.0-SNAPSHOT -retrieve "distrib/[artifact]-[revision](-[classifier]).[ext]"

The retrieve option of the ivy command details how the downloaded files should be stored locally: ivy命令的retrieve选项详细说明了如何在本地存储下载的文件:

-- distrib
   |-- cometd-api-1.0-SNAPSHOT.jar
   |-- cometd-jetty-client-1.0-SNAPSHOT.jar
   |-- cometd-jetty-client-1.0-SNAPSHOT-javadoc.jar
   |-- cometd-jetty-client-1.0-SNAPSHOT-sources.jar
   |-- cometd-jetty-server-1.0-SNAPSHOT.jar
   |-- jetty-6.1.15.jar
   |-- jetty-client-6.1.15.jar
   |-- jetty-sslengine-6.1.15.jar
   |-- jetty-util5-6.1.15.jar
   |-- jetty-util-6.1.15.jar
   `-- servlet-api-2.5-20081211.jar

The correct timestamped artifact is retrieved but the "SNAPSHOT" revision number is preserved, which is what I understand you're trying to do. 检索到正确的带时间戳的工件,但保留了“SNAPSHOT”修订版号,这是我理解您正在尝试执行的操作。

The ivysettings file details the repositories to be used when downloading artifacts: ivysettings文件详细说明了下载工件时要使用的存储库:

<ivysettings>
    <settings defaultResolver="repos"/>
    <resolvers>
        <chain name="repos">
            <ibiblio name="central" m2compatible="true"/>
            <ibiblio name="cometd-snapshot" root="https://oss.sonatype.org/content/repositories/cometd-snapshots/" m2compatible="true"/>
        </chain>
    </resolvers>
</ivysettings>

可以在此处找到Maven Resolve Nexus REST API的文档: https//maven.java.net/nexus-core-documentation-plugin/core/docs/rest.artifact.maven.resolve.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM