java Sonatype Nexus 3 - 获取最新快照

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37280818/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:22:36  来源:igfitidea点击:

Sonatype Nexus 3 - get latest snapshot

javamavennexusnexus3

提问by Daniel

We've just upgraded out nexus installation to the latest release (3.x). Is there any way to get the latest version of a given snapshot artifact? Nexus 2 had a nice API which is not supported anymore.

我们刚刚将 nexus 安装升级到最新版本 (3.x)。有没有办法获得给定快照工件的最新版本?Nexus 2 有一个很好的 API,它不再受支持。

Same question (but for the old version) has been answered here: Sonatype Nexus REST Api fetch latest build version

同样的问题(但对于旧版本)已在此处回答: Sonatype Nexus REST Api fetch latest build version

Any ideas are highly appreciated.

任何想法都受到高度赞赏。

Best, Daniel

最好的,丹尼尔

回答by Peter Lynch

Nexus 2 had a nice API which is not supported anymore.

Nexus 2 有一个很好的 API,它不再受支持。

It sounds like you are referring to these:

听起来您指的是这些:

/service/local/artifact/maven/content
/service/local/artifact/maven/redirect

If you're asking to find the latest x.y.z-SNAPSHOT version where the x, y, z are guessed - Nexus never had this functionality (it worked only for plugins).

如果您要求找到猜测 x、y、z 的最新 xyz-SNAPSHOT 版本 - Nexus 从未拥有此功能(它仅适用于插件)。

This is simply untrue - see the following article which shows clearly you can specify LATEST, RELEASE or SNAPSHOT base versions.

这完全是不真实的 - 请参阅以下文章,其中清楚地表明您可以指定 LATEST、RELEASE 或 SNAPSHOT 基本版本。

https://support.sonatype.com/hc/en-us/articles/213465488-How-can-I-retrieve-a-snapshot-if-I-don-t-know-the-exact-filename-

https://support.sonatype.com/hc/en-us/articles/213465488-How-can-I-retrieve-a-snapshot-if-I-don-t-know-the-exact-filename-

It's possible but not in a 1-liner.

这是可能的,但不是 1-liner。

Yes - unless you have a tool handy such as artifact-resolverwhich does uses a one line command to fetch an artifact.

是的 - 除非您有一个方便的工具,例如artifact-resolver,它确实使用单行命令来获取工件。

回答by Kevin Pauli

What a joke re: Nexus 3 having no REST API.

真是个笑话:Nexus 3 没有 REST API。

I found a hack that alleviates my problem. Turns out that ansible has a nice maven_artifactmodule that is somehow able to figure out the latest snapshot. And you can run ansible locally. So it ends up looking like this:

我找到了一个可以缓解我的问题的黑客。事实证明ansible有一个不错的maven_artifact模块,它能够以某种方式找出最新的快照。你可以在本地运行 ansible。所以它最终看起来像这样:

ansible all -i localhost, -c local -m maven_artifact -a "repository_url=https://my-nexus/repository/maven-snapshots/ group_id=com.whatever artifact_id=my-artifact version=2.0-SNAPSHOT dest=./my-artifact.jar"

回答by user1717259

Asof April 2019 there IS a REST API in Sonatype Nexus 3 for accessing the latest artefact

Asof 2019 年 4 月在 Sonatype Nexus 3 中有一个 REST API 用于访问最新的人工制品

Documentation is here

文档在这里

http://community.sonatype.com/t/nxrm-3-16-rest-search-and-filtering-enhancements/1586

http://community.sonatype.com/t/nxrm-3-16-rest-search-and-filtering-enhancements/1586

Use this endpoint /service/rest/v1/search/assets/downloadwith repository, groupand namearguments. Sorting by versionwill get you the latest timestamped snapshot.

将此端点/service/rest/v1/search/assets/downloadrepository,groupname参数一起使用。排序依据version将为您提供最新的带时间戳的快照。

https://nexus.blahblah.com/service/rest/v1/search/assets/download?repository=maven-snapshots&group=com.my.company&name=myArtefact&sort=version&direction=desc

https://nexus.blahblah.com/service/rest/v1/search/assets/download?repository=maven-snapshots&group=com.my.company&name=myArtefact&sort=version&direction=desc

回答by Stanislav Bashkyrtsev

If you ask for x.y.z-SNAPSHOTthen by default the latest x.y.z-timestampsnapshot version will be downloaded. No need to do anything additional

如果您要求,x.y.z-SNAPSHOT则默认情况下x.y.z-timestamp将下载最新的快照版本。无需做任何额外的事情

If you're asking to find the latest x.y.z-SNAPSHOTversion where the x, y, zare guessed - Nexus never had this functionality(it worked only for plugins). And I don't think there is any good use case for this. If this is needed, you're probably doing something wrong. You always should work with a specific version. Actually even for the 1st functionality I can't think of good use cases.

如果您要求找到猜测, ,的最新x.y.z-SNAPSHOT版本- Nexus 从来没有这个功能(它只适用于插件)。我认为这没有任何好的用例。如果需要这样做,您可能做错了什么。您应该始终使用特定版本。实际上,即使对于第一个功能,我也想不出好的用例。xyz

回答by didlich

recently we faced the same problem with nexus version 3.12.1-01, so there is definitely not rest api to get latest snapshot directly

最近我们在nexus 3.12.1-01版本遇到了同样的问题,所以肯定没有rest api直接获取最新的快照

we were able to solve the problem using python one liner

我们能够使用 python one liner 解决问题

JSON_RESPONSE=$(curl -u un:pw -X GET "http://nexus-host/nexus/service/rest/beta/search/assets?maven.groupId=sample.group.id&maven.artifactId=sample&maven.extension=jar" -H  "accept: application/json")

echo $JSON_RESPONSE | python -c 'import sys, json; lines = json.load(sys.stdin)["items"]; sortedlines = sorted(lines, key=lambda k: k["downloadUrl"], reverse=True); print(sortedlines[0]["downloadUrl"])'

hope it helps

希望能帮助到你

回答by rbjorklin

I've put together a groovy script that can be uploaded to Nexus which solves this particular issue with a POST request.

我已经整理了一个可以上传到 Nexus 的 groovy 脚本,它通过 POST 请求解决了这个特定问题。

You can find the script and some usage instructions here: https://github.com/rbjorklin/resolve-latest-nexus-artifact

你可以在这里找到脚本和一些使用说明:https: //github.com/rbjorklin/resolve-latest-nexus-artifact

回答by Martin Hatas

You can download with curl

你可以用 curl 下载

curl -L --header 'Accept: application/json' "https://${NEXUS_URL}/service/rest/beta/search/assets/download?repository=${NEXUS_REPO_NAME}&maven.groupId=${MVN_GROUP_ID}&maven.artifactId=${MVN_ARTIFACT_ID}&maven.baseVersion=${APP_VERSION}&maven.extension=${MVN_EXTENSION}"

回答by barth

Bash one-liner using curl, jq, sortand tail:

Bash 单行使用curl, jq,sorttail

NEXUS_URL=https://your-nexus.com
MAVEN_REPO=maven-snapshots
GROUP_ID=...
ARTIFACT_ID=...
VERSION=2.0.1-SNAPSHOT
FILE_EXTENSION=jar

download_url=$(curl -X GET "${NEXUS_URL}/service/rest/v1/search/assets?repository=${MAVEN_REPO}&maven.groupId=${GROUP_ID}&maven.artifactId=${ARTIFACT_ID}&maven.baseVersion=${VERSION}&maven.extension=${FILE_EXTENSION}" -H  "accept: application/json"  | jq -rc '.items | .[].downloadUrl' | sort | tail -n 1)

wget $download_url

回答by seckin

Using OSS 3.21.2-03 I have retrieved latest snapshot with following url on a zip extension file :

使用 OSS 3.21.2-03 我在 zip 扩展文件中使用以下 URL 检索了最新快照:

{nexus_host}/service/rest/v1/search/assets/download?sort=version&repository={repository_name}&group={group_id}&name={artifact-id}&maven.extension=zip

回答by Jon Freedman

It's possible but not in a 1-liner. You need to fetch the maven-metadata.xml for each snapshot artifact you're after (note that multi-module projects have different timestamps for each module including the parent).

这是可能的,但不是 1-liner。您需要为您所追求的每个快照工件获取 maven-metadata.xml(请注意,多模块项目对于每个模块(包括父模块)具有不同的时间戳)。

We use xlstprocto extract the relevant variables so we are still able to run from the command line without heavyweight tools like maven or ivy to do the resolution.

我们使用xlstproc来提取相关变量,因此我们仍然可以从命令行运行,而无需像 maven 或 ivy 这样的重量级工具来进行解析。