如何强制 Maven 从中央存储库下载 maven-metadata.xml?

发布于 2024-08-02 00:17:39 字数 383 浏览 3 评论 0原文

我想要做的是强制 Maven 为本地存储库中的每个工件下载“maven-metadata.xml”。

默认 Maven 行为是仅从远程存储库下载元数据(请参阅

为什么我要这样做:

目前我有一个在构建机器上运行的远程存储库。 我所说的远程存储库是指位于构建机器中的目录,其中包含构建 Maven 项目所需的所有依赖项。 请注意,我没有使用像 Nexus 这样的存储库管理器,该存储库只是我上传到构建计算机的本地存储库的副本。

但是,由于我的本地存储库不包含“maven-metadata.xml”文件,因此构建机器存储库中也缺少这些元数据文件。 如果我可以从中央存储库检索元数据文件,那么就可以将工作远程存储库上传到我的构建机器。

What I want to do is to force Maven to download the 'maven-metadata.xml' for each artifact that I have in my local repository.

The default Maven behaviour is to download only metadata from remote repositories (see this question).

Why I want to do that:

Currently I have a remote repository running in a build machine. By remote repository I mean a directory located in the build machine that contains all dependencies that I need to build my Maven projects. Note that I'm not using a repository manager like Nexus, the repository is just a copy of a local repository that I have uploaded to my build machine.

However, since my local repository did not contain the 'maven-metadata.xml' files, these metadata files are also missing in the build machine repository. If I could retrieve the metadata files from the central repository, then it would be possible to upload a working remote repository to my build machine.

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

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

发布评论

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

评论(4

归途 2024-08-09 00:17:39

您不想从公共存储库获取元数据,它将包含给定工件的所有可用版本,而您的存储库将包含版本的某些子集。

值得指出的是,使用存储库管理器确实会更好。 通过以下步骤,您可以一次性生成工件元数据。 但如果您的需求发生变化,您将不得不重复该过程或手动更新文件,那么为什么不直接使用管理器呢? Nexus 可以独立运行并且占用空间非常小。


即使您不打算使用 Nexus 作为存储库管理器,您仍然可以使用它来生成元数据。

  1. 首先安装 Nexus。
  2. 找到 nexus 工作目录(默认为 ${user.home}/sonatype-work。
  3. 将本地存储库内容复制到 nexus-work/releases 子目录。
  4. 启动 Nexus 并在浏览器中连接到 Nexus 主页(默认情况下 http://localhost:8081/nexus)
  5. 使用管理员帐户登录(密码 admin123)
  6. 单击存储库链接 稍后
  7. 选择发布存储库,右键单击并单击重建元数据

您就可以为所有工件生成元数据,然后您可以将它们复制到您需要的位置。并卸载 Nexus。

You don't want to get the metadata from the public repositories, it will contain all the versions available of a given artifact, whereas your repository will have some subset of the releases.

It's worth pointing out that you really would be better off with a repository manager. The following steps allow you to generate your artifact metadata once. But if your needs change, you'll have to repeat the process or update the files manually, so why not just use a manager? Nexus can run standalone and has a very small footprint.


Even if you're not planning on using Nexus for a repository manager, you can still use it to generate your metadata.

  1. First install Nexus.
  2. Locate the nexus work directory (by default ${user.home}/sonatype-work.
  3. Copy your local repository contents to the nexus-work/releases sub-directory.
  4. Start Nexus and connect to the Nexus home page in the browser (by default http://localhost:8081/nexus)
  5. Log in using the admin account (password admin123)
  6. Click on the repositories link on the left hand side.
  7. Select the Releases repository, right-click and click Rebuild Metadata

In a few moments you should have the metadata generated for all the artifacts. You can then copy them to wherever you need them to be and uninstall Nexus.

墨落成白 2024-08-09 00:17:39

默认存储库在 super pom.xml< 中定义/a> 默认情况下所有 pom 都继承自它。

如果本地意味着您只想使用 ~/.m2/repos/* 则在离线模式下工作。 将 true 添加到您的 settings.xml

如果本地指的是您的本地服务器,您可以安装一个存储库像 Nexus 这样的管理器,修改您的设置文件以在“镜像”下使用 Nexus,如下所示:

<mirror>
  <id>central-proxy</id>
  <mirrorOf>central</mirrorOf>
  <url>my/local/nexus/server</url>
</mirror>

并禁用 Nexus 中不需要的远程存储库。

The default repositories are defined in the super pom.xml that all poms inherit from by default.

If by local you mean you want to only use ~/.m2/repos/* then work in offline mode. Add <offline>true</offline> to your settings.xml

If by local you mean your local server, you could install a repository manager like Nexus, modify your settings file to use nexus under "mirrors" like this:

<mirror>
  <id>central-proxy</id>
  <mirrorOf>central</mirrorOf>
  <url>my/local/nexus/server</url>
</mirror>

And disable remote repositories you don't want in Nexus.

莳間冲淡了誓言ζ 2024-08-09 00:17:39

我发现的一件事是有人正在对 jarvana 进行初始搜索并将其放置在 pom 中,导致出现元数据错误消息。 这.....

   <!-- <repository>
        <id>jarvana</id>
        <url>http://www.jarvana.com/jarvana/browse/</url>
    </repository> -->

修复了它并且错误消失了。

One thing I found is someone was doing an initial search of jarvana and had placed this within the pom, causing a metadata error message to occur. This ...

   <!-- <repository>
        <id>jarvana</id>
        <url>http://www.jarvana.com/jarvana/browse/</url>
    </repository> -->

..fixed it and the error went away.

儭儭莪哋寶赑 2024-08-09 00:17:39

存储库管理器很棒,但我不想在我的笔记本电脑上安装和运行它。 我只是想节省资源。
所以,我的解决方案如下:

  1. 将存储库安装为神器(https://www.jfrog.com/artifactory
  2. 通过此服务器(localhost:8081)运行materialize,
  3. 通过远程服务器(center.maven.org)运行materialize,
  4. 将artifactory
  5. 合并的缓存内容下载到文件夹:从步骤4下载的文件夹和~/.m2/repository的文件夹。

现在我有一个离线存储库,包含完整内容(二进制、源代码、xml、md5、sha1)

Repository manager is great but I don't want install and run it on my laptop. I just want to save resource.
So, my solution is below:

  1. install repository as artifactory (https://www.jfrog.com/artifactory)
  2. run materialize thru this server (localhost:8081)
  3. run materialize thru remote server (center.maven.org)
  4. download cache content of artifactory
  5. merger to folder: folder download from step 4 and folder at ~/.m2/repository.

Now I have a repository offline with full content (binary, source, xml, md5, sha1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文