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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1273266/
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-10-29 15:53:39  来源:igfitidea点击:

How to force Maven to download maven-metadata.xml from the central repository?

javamaven-2maven-metadata

提问by Alceu Costa

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.

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

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

Maven 的默认行为是仅从远程存储库下载元数据(请参阅此问题)。

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.

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

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.

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

回答by Rich Seller

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.

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



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

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

  1. First installNexus.
  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 Nexusand 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 repositorieslink on the left hand side.
  7. Select the Releases repository, right-click and click Rebuild Metadata
  1. 首先安装Nexus。
  2. 找到 nexus 工作目录(默认为 ${user.home}/sonatype-work。
  3. 将您的本地存储库内容复制到 nexus-work/releases 子目录。
  4. 启动 Nexus并在浏览器中连接到 Nexus 主页(默认为http://localhost:8081/nexus
  5. 使用管理员帐户(密码 admin123)登录
  6. 单击左侧的存储库链接。
  7. 选择 Releases 存储库,右键单击并单击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.

片刻之后,您应该会为所有工件生成元数据。然后,您可以将它们复制到您需要的任何位置并卸载 Nexus。

回答by sal

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

默认存储库在所有 pom 默认继承的super pom.xml中定义。

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

如果通过本地你的意思是你只想使用 ~/.m2/repos/* 然后在离线模式下工作。添加 <offline>true</offline>到您的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:

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

<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.

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

回答by RichMeister

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 ...

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

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

..fixed it and the error went away.

..修复它,错误消失了。

回答by Hiep Lq

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.
  1. 将存储库安装为 artifactory ( https://www.jfrog.com/artifactory)
  2. 通过此服务器运行实现(本地主机:8081)
  3. 通过远程服务器(center.maven.org)运行物化
  4. 下载神器缓存内容
  5. 合并到文件夹:从步骤 4 下载的文件夹和 ~/.m2/repository 中的文件夹。

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

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