使用本地工件更新 Nexus 存储库
我最近将一些 Maven 工件直接下载到我的本地存储库 (.m2/repository)。 现在我安装了 Nexus Repository Manager,需要填充其存储空间,而无需再次下载所有工件。有没有一种方法可以将 Nexus 存储库更新为本地存储库。 我不想简单地复制它们,因为 Nexus 分离了有关其公共服务器(中央、codehaus 等)的工件,而本地存储库结构则不然。
更新: 同时,我将工件从本地存储库复制到 Nexus 存储(公共存储库)。我可以通过 Nexus Web 应用程序浏览到工件,但 Maven 无法解析来自 Nexus 的工件。 我需要特别注册吗?我重新索引了公共存储库并重新启动了 Nexus 多次 - 没有任何变化。
i recently downloaded some maven artifacts directly to my local repository (.m2/repository).
Now i installed the Nexus Repository Manager and need to fill its storage without to download all the artifacts again. Is there a way to update the Nexus repository with the local one.
I don't want to simply copy them because Nexus separate artifacts concerning their public servers (central, codehaus, etc.) and the local repository structure doesn't.
Update:
Meanwhile i copied the the artifacts from the local repository to the Nexus storage (public repository). I can browse to the artifacts via the Nexus webapp, but Maven somehow can't resolve the artifacts from Nexus.
Do i need to register them particularly? I re-indexed the public repository and restarted Nexus multiple times - no changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

Nexus 有多种类型的存储库:托管存储库(真正存储 Maven 工件的存储库)、代理存储库(当请求工件时将流量重定向到其他远程存储库)、< em>虚拟存储库(maven1存储库的一个适配器[超出了这个问题的范围])。您还可以创建可以从其任何聚合中提供工件的存储库组(
公共
存储库就是其中之一)。此外,Nexus 根据其发布政策将其存储库分为快照和发布。前者仅存储快照工件;而后者理论上可以同时存储快照和版本,但当存储库非常大并且包含快照时,它实际上会出现错误。
为了托管您的工件,您需要:
第一:将本地存储库分为两部分:一个包含快照,另一个包含版本。如果您的存储库非常大,Nexus 存储库转换工具将为您提供帮助:
下载后,您只需执行 java -jar nexus-repository-conversion-tool-1.8.0.1-cli.jar -rSource -oTarget 其中
Source
是包含要移动到 nexus 的本地存储库的目录,Target
是现有的、空的且可写的目录,转换工具将在其中保留分割的存储库。假设源目录是repository
并且目标是temp
,它将创建temp/repository-snapshots
和temp/repository-releases< /代码> 目录。
第二:将拆分的存储库移至 nexus。并将它们保留在
${NEXUS_HOME}/sonatype-work/nexus/storage
中,或者您的 nexus 安装配置为存储存储库的任何位置。第三:创建两个托管存储库,其 ID 与您在第二步中移动的存储库相同。 (在示例
repository-snapshots
和repository-releases
中)如果您的存储库仅包含版本,您的解决方案可能会起作用,但您将犯另一个错误。尽管 Nexus 为每个存储库存储工件,但那些非托管存储库的存储仅用于缓存目的(如
public
存储库的情况),您必须将内容复制到为了工作而接待了一位。Nexus has several type of repositories: hosted repositories (those that really store maven artifacts), proxy repositories (that redirect traffic to other remote repositories when an artifact is requested), virtual repositories (a mere adapter of maven1 repositories [out of the scope of this question]). you can also create repository groups that can serve artifacts from any of its aggregates (the
public
repository is one of these).In addition, nexus divides their repositories according to its publishing policy into snapshots and releases. The former stores only snapshot artifacts; while the latter, in theory, can store both snapshots and releases, but it actually behaves buggy when the repo is very big and contains snapshots.
In order to host your artifacts you need to:
First: Divide your local repository into two: one containing the snapshots, and another containing the releases. Nexus repository convertion tool will help you if your repo is very big:
Once downlaoded you can just execute
java -jar nexus-repository-conversion-tool-1.8.0.1-cli.jar -rSource -oTarget
whereSource
is the directory that contains the local repository to move to nexus, andTarget
is an existing, empty and writable directory where the convertion tool will leave the splitted repositories. Provided that source directory isrepository
and Target istemp
, it will createtemp/repository-snapshots
andtemp/repository-releases
directories.Second: move your splitted repos to nexus. And leave them in
${NEXUS_HOME}/sonatype-work/nexus/storage
, or wherever your nexus installation is configured to store the repositories.Third: create two hosted repositories with the same id as the repos you moved in the second step. (in the example
repository-snapshots
andrepository-releases
)If your repo would only contained releases, your solution could have worked, but you will have commited another mistake. Although nexus stores artifacts for every repository, the storage of those that aren't hosted repos is just for caching purposes (as in the case of the
public
repository), you would have to copied your contents to a hosted one in order to work.