使用 Nexus REST API 获取给定 groupid/artifactId 的最新工件版本

发布于 12-12 01:36 字数 369 浏览 0 评论 0 原文

我正在尝试使用 nexus REST api 来获取最新版本的 Maven 工件。我可以使用 http://repo.local/service/local/data_index?a=local-turbogears-server&from=0&g=com.turbo&c 浏览到我正在寻找的特定版本=bin&v=1.1.9 如果我删除版本参数,我可以看到每个版本。但是,当我尝试使用 RELEASE 或 LATEST 作为版本时,它会返回零结果。 我检查了 nexus 磁盘上的 maven-metadata.xml,其中有最新和发布的条目。我还需要采取其他步骤才能返回最新版本吗?

我目前使用的是:

Nexus v.1.9.2

I am trying to use the nexus REST api to get the latest version of a maven artifact. I am able to browse to the specific version I am looking for using http://repo.local/service/local/data_index?a=local-turbogears-server&from=0&g=com.turbo&c=bin&v=1.1.9 and if I remove the version parameter I can see every version. However when I try and use RELEASE or LATEST as the version then it returns zero results.
I checked the maven-metadata.xml on disk in nexus and there are entries for latest and release. Is there another step I need to take to return the latest version?

I am currently using:

Nexus v. 1.9.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

十二 2024-12-19 01:36:55

以下 URL 将检索最新版本的 log4j 1.2.x:

"="">http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST

已记录 此处

使用curl更新

示例:

curl -L "http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST" -o log4j.jar

Log4j2 更新

Log4j 1.2 自 2015 年夏季起已停产,已知在 Java 9 中已损坏。

以下是 Log4j 工件的链接:

The following URL will retrieve the latest version of log4j 1.2.x:

http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST

Documented here

Update

Example using curl:

curl -L "http://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=log4j&a=log4j&v=LATEST" -o log4j.jar

Update for Log4j2

Log4j 1.2 is EOL since summer 2015 and is known to be broken in Java 9.

Here is the link for the Log4j artifacts:

泪痕残 2024-12-19 01:36:55

在 Nexus LATEST 中,设计为与 maven 插件配合使用,而不是与常规工件配合使用。 Nexus 根本不保证最新版本在其他情况下也能正常工作。如果现在它返回您正确版本的工件,那么明天它可能会停止工作,例如,如果您为 Nexus 存储库运行重建元数据。您是否想要依赖随时可能中断的机制(例如在发布过程中?)。我怀疑。阅读这篇文章了解更多信息。

为了找到最新的工件版本,您应该编写自己的脚本来调用搜索 API 并根据需要对工件版本进行排序。或者您可以为 Nexus 编写自己的插件。

或者,如果您的工作流程允许,您可以使用快照而不是发布版本。如果您不增加数字部分,则 xyz-SNAPSHOT 将始终返回最新的二进制文件。

最后一点:不要使用最新版本的工件,在绝大多数情况下,如果您有这样的用例,那么您的部署(或您正在做的任何事情)就会出现问题。一般来说,您应该知道要使用的确切版本。

In Nexus LATEST is designed to work with maven plugins rather than with regular artifacts. Nexus simply doesn't guarantee the LATEST to work in other cases. If right now it returns you the correct version of the artifact, tomorrow this may stop working e.g. if you run Rebuild Metadata for the Nexus repository. Do you want to rely on the mechanism that may break at any moment (e.g. during the release process?). I doubt. Read this article for more insight.

In order to find the LATEST artifact version you should either write your own script to invoke Search API and sort artifact versions as you want. Or you can write your own plugin for Nexus.

Alternatively, if your workflow allows that, you can use SNAPSHOTs instead of release versions. If you don't increment numeric part, then x.y.z-SNAPSHOT will always return the latest binary.

Last point: do not use latest versions of artifacts, in the vast majority of cases if you have such a use case, then something is wrong with your deployments (or whatever you're doing). In general you should know the exact version you're going to use.

强者自强 2024-12-19 01:36:55

该答案已复制自: https://stackoverflow.com/a/39485361/1450799

我有 Linux 操作系统,并且我无法访问 REST API,因此我使用以下命令从 Nexus 获取最新版本的快照:

来自 WSO2 存储库的示例快照 maven-metadata.xml:

$ curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml"
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>org.wso2.is</groupId>
  <artifactId>wso2is</artifactId>
  <versioning>
    <latest>5.3.0-SNAPSHOT</latest>
    <release></release>
    <versions>
      <version>5.1.0-SNAPSHOT</version>
      <version>5.2.0-SNAPSHOT</version>
      <version>5.3.0-SNAPSHOT</version>
    </versions>
    <lastUpdated>20160914062755</lastUpdated>
  </versioning>
</metadata>

从 maven-metadata.xml 内的最新 XML 标签提取:

curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml" | \
grep "<latest>.*</latest>" | \
sed -e "s#\(.*\)\(<latest>\)\(.*\)\(</latest>\)\(.*\)#\3#g"

从 maven-metadata.xml 内的版本 XML 标签提取:

curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml" | \
grep "<version>.*</version>" | \
sort --version-sort | uniq | tail -n1 | \
sed -e "s#\(.*\)\(<version>\)\(.*\)\(</version>\)\(.*\)#\3#g"

截至 2016 年 9 月 14 日,这两个命令的结果是:

5.3.0-SNAPSHOT

This answer has been copied from: https://stackoverflow.com/a/39485361/1450799

I have Linux OS and I do not have access to REST API, so I used following commands to get the latest version of snapshots from Nexus:

An example snapshots maven-metadata.xml from WSO2 repository:

$ curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml"
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>org.wso2.is</groupId>
  <artifactId>wso2is</artifactId>
  <versioning>
    <latest>5.3.0-SNAPSHOT</latest>
    <release></release>
    <versions>
      <version>5.1.0-SNAPSHOT</version>
      <version>5.2.0-SNAPSHOT</version>
      <version>5.3.0-SNAPSHOT</version>
    </versions>
    <lastUpdated>20160914062755</lastUpdated>
  </versioning>
</metadata>

Extracting from latest XML tag inside maven-metadata.xml:

curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml" | \
grep "<latest>.*</latest>" | \
sed -e "s#\(.*\)\(<latest>\)\(.*\)\(</latest>\)\(.*\)#\3#g"

Extracting from version XML tag inside maven-metadata.xml:

curl -s "http://maven.wso2.org/nexus/content/repositories/snapshots/org/wso2/is/wso2is/maven-metadata.xml" | \
grep "<version>.*</version>" | \
sort --version-sort | uniq | tail -n1 | \
sed -e "s#\(.*\)\(<version>\)\(.*\)\(</version>\)\(.*\)#\3#g"

The result of both of the commands until today 14 Sep 2016 is:

5.3.0-SNAPSHOT
唯憾梦倾城 2024-12-19 01:36:55

在尝试使用 LATEST 版本的 REST 服务后,发现它并不总是有效(请参阅 @Stanislav 回复)我最终创建了这个单行Linux命令来解析metadata.xml文件:

wget -O - -o /dev/null https://repo1.maven.org/maven2/org/brutusin/wava/maven-metadata.xml | grep -Po '(?<=<version>)([0-9\.]+(-SNAPSHOT)?)' | sort --version-sort -r | head -n 1

只需将 更改为适当的url,它应该适合您。

干杯

After trying the REST service with the LATEST version, and discovering it doesn't always work (See @Stanislav response) I ended up creating this one-liner Linux command for parsing the metadata.xml file:

wget -O - -o /dev/null https://repo1.maven.org/maven2/org/brutusin/wava/maven-metadata.xml | grep -Po '(?<=<version>)([0-9\.]+(-SNAPSHOT)?)' | sort --version-sort -r | head -n 1

Just change the to the appropiate url, and it should work for you.

Cheers

丶情人眼里出诗心の 2024-12-19 01:36:55

对于最新版本的 Nexus(自 3.16.0 起):使用浏览器从 mavenreleases 存储库下载最新版本(以 zip 文件格式存储)的示例:

http://<YourNexusUrl>/service/rest/v1/search/assets/download?sort=version&repository=maven-releases&maven.groupId=<yourGroupID>&maven.artifactId=<yourArtifactID>&maven.extension=zip

使用curl:

curl -L -X GET "http://<YourNexusUrl>/service/rest/v1/search/assets/download?sort=version&repository=maven-releases&maven.groupId=<yourGroupID>&maven.artifactId=<yourArtifactID>&maven.extension=zip" --output myZip.zip

For latest versions of Nexus (since 3.16.0): Example of downloading the latest version (stored in format of zip file) from maven releases repository, using browser:

http://<YourNexusUrl>/service/rest/v1/search/assets/download?sort=version&repository=maven-releases&maven.groupId=<yourGroupID>&maven.artifactId=<yourArtifactID>&maven.extension=zip

Using curl:

curl -L -X GET "http://<YourNexusUrl>/service/rest/v1/search/assets/download?sort=version&repository=maven-releases&maven.groupId=<yourGroupID>&maven.artifactId=<yourArtifactID>&maven.extension=zip" --output myZip.zip

李不 2024-12-19 01:36:55

在 Nexus API 的最新版本中记录了检索组件最新版本的方法,按存储库、组、工件和基本版本进行过滤

示例:
http://localhost:8081/service/rest/v1/search/assets/download?sort=version&repository=maven-snapshots&maven.groupId=org.foo.bar&maven.artifactId=project&maven.baseVersion= 1.2.3-SNAPSHOT&maven.extension=jar

参考文档:
https://help.sonatype.com/ repomanager3/rest-and-integration-api/search-api#SearchAPI-SearchComponents

In the last version of Nexus API is documented the way to retrieve the latest version of a component, filtering by repository, group, artifact and base version

Example:
http://localhost:8081/service/rest/v1/search/assets/download?sort=version&repository=maven-snapshots&maven.groupId=org.foo.bar&maven.artifactId=project&maven.baseVersion=1.2.3-SNAPSHOT&maven.extension=jar

Reference documentation:
https://help.sonatype.com/repomanager3/rest-and-integration-api/search-api#SearchAPI-SearchComponents

北凤男飞 2024-12-19 01:36:55

使用“jq”从 Nexus 下载最新工件的另一种选择

artifact_url="https://<nexus url>/service/rest/v1/search/assets?group=<group name>&name=<artifact_name>&maven.baseVersion=<artifact_base_version>&maven.extension=zip"

# Get data of the latest artifact
artifact_data=$(curl -s "${artifact_url}" | jq '.items |= sort_by(.lastModified)' | jq '.items[-1]' --raw-output)

# Get the download Url of the artifact
artifact_download_url=$(echo "${artifact_data}" | jq '.downloadUrl' --raw-output)

# Downloads
curl --create-dirs -LsSf -o "./artifacts/<artifact name>.zip" "${artifact_download_url}"

Another alternative of downloading the latest artifact from Nexus using "jq"

artifact_url="https://<nexus url>/service/rest/v1/search/assets?group=<group name>&name=<artifact_name>&maven.baseVersion=<artifact_base_version>&maven.extension=zip"

# Get data of the latest artifact
artifact_data=$(curl -s "${artifact_url}" | jq '.items |= sort_by(.lastModified)' | jq '.items[-1]' --raw-output)

# Get the download Url of the artifact
artifact_download_url=$(echo "${artifact_data}" | jq '.downloadUrl' --raw-output)

# Downloads
curl --create-dirs -LsSf -o "./artifacts/<artifact name>.zip" "${artifact_download_url}"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文