Maven 存储库镜像

发布于 2024-10-17 04:16:01 字数 850 浏览 2 评论 0原文

通常,我在 Maven settings.xml 中配置了以下镜像。

<mirror>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
  <mirrorOf>*</mirrorOf>
</mirror>

我的理解是,该镜像会阻止 Maven 从互联网下载依赖项,即它只会在此内部存储库中查找它们。

然而,每当我想添加一个不在这个内部存储库中的依赖项时,我必须注释掉上面的文本并将以下内容添加到项目的 pom.xml

<repository>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
</repository>

当我进行这些更改时,Maven 将检查本地仓库中是否有依赖项,如果没有找到,则从互联网下载到本地仓库。一旦获得了所需的依赖项,我就将配置更改回来。

有没有办法获得我想要的行为 - 始终检查内部存储库,然后检查公共(互联网)存储库 - 无需将 添加到每个项目的 pom.xml ?

理想情况下,我想在 settings.xml 中指定此存储库一次,但似乎您只能在那里配置镜像。

Normally, I have the following mirror configured in my Maven settings.xml

<mirror>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
  <mirrorOf>*</mirrorOf>
</mirror>

My understanding is that this mirror prevents Maven from downloading dependencies from the internet, i.e. it will only look for them in this internal repository.

However, whenever I want to add a dependency that isn't in this internal repository, I have to comment out the text above and add the following to the project's pom.xml

<repository>
  <id>internal-repository</id>
  <url>http://build.idaho.local/wtp_repository</url>
</repository>

When I make these changes Maven will check for dependencies in the local repo, and if not found, download them from the internet to the local repo. Once I have the dependencies I need, I then change my configuration back.

Is there a way to get the behaviour I want - always check the internal repo, then the public (Internet) repos - without having to add the <repository> to every project's pom.xml?

Ideally I would like to specify this repository once in settings.xml, but it seems that you can only configure mirrors there.

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

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

发布评论

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

评论(5

深府石板幽径 2024-10-24 04:16:01

您可以尝试将maven配置为仅将镜像用于中央存储库或排除由某些id标识的存储库。

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>central</mirrorOf>
</mirror>

或者

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>*,!internal-repository</mirrorOf>
</mirror>

这些示例改编自 maven 设置镜像设置指南

You could try to configure maven to use the mirror only for the central repository or to exclude the repository identified by some id.

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>central</mirrorOf>
</mirror>

Or

<mirror>
    <id>internal-mirror</id>
    <url>http://build.idaho.local/wtp_repository</url>
   <mirrorOf>*,!internal-repository</mirrorOf>
</mirror>

The examples were adapted from maven settings and guide to mirror settings.

骄兵必败 2024-10-24 04:16:01

这个问题很老了,但无论如何:

在你的settings.xml中放置一个,使用元素指定你的内部存储库

...
    <profile>
        <id>devel-repos</id>

        <repositories>
            <repository>
                <id>repo-release</id>
                <url>http://repohost:repoport/path/to/release/repo</url>
            </repository>
            <repository>
                <id>repo-snapshot</id>
                <url>http://repohost:repoport/path/to/snapshot/repo</url>
            </repository>
        </repositories>
    </profile>
...

然后设置上面的内容配置文件为 。这将为每个 Maven 调用激活配置文件。

...
<activeProfiles>
    <activeProfile>devel-repos</activeProfile>
</activeProfiles>
...

这并不能避免多个存储库定义,但它为您提供了最重要的事情:所有内容都集中在 settings.xml 中,并且您的 pom.xml 是干净的(并且可移植) 。

This question is quite old, but anyway:

Put a <profile> in your settings.xml that specifies your internal repository using the <repository> element

...
    <profile>
        <id>devel-repos</id>

        <repositories>
            <repository>
                <id>repo-release</id>
                <url>http://repohost:repoport/path/to/release/repo</url>
            </repository>
            <repository>
                <id>repo-snapshot</id>
                <url>http://repohost:repoport/path/to/snapshot/repo</url>
            </repository>
        </repositories>
    </profile>
...

Then set the above profile as <activeProfile>. This will activate the profile for every maven invocation.

...
<activeProfiles>
    <activeProfile>devel-repos</activeProfile>
</activeProfiles>
...

This does not avoid multiple repository definitions, but it gives you the most important thing: everything is centralized in settings.xml and your pom.xmls are clean (and portable).

亽野灬性zι浪 2024-10-24 04:16:01

您可能没有正确配置或使用镜像。

理想情况下,您指定的镜像应该是一个存储库管理器,它应该透明地下载从互联网上的各个存储库请求依赖项并将其缓存,从而允许从镜像进行后续下载。

It looks like you may not have configured or using the mirror correctly.

Ideally, what you specify as the mirror should be a repository manager, which should transparently download the requested dependency from various repositories in the internet and cache it, thereby allowing subsequent downloads to happen from the mirror.

飘落散花 2024-10-24 04:16:01

将存储库部分添加到 super pom.xml 中。并让所有的项目都从super pom延伸出来。

因此,每个其他项目 pom 都会有一个父部分从超级 pom 扩展,如下所示。

<parent>
    <groupId>com.ddd.ddd.ddd</groupId>
    <artifactId>ddd-ddd-parent</artifactId>
    <version>1.1.1-SNAPSHOT</version>
    <relativePath>./config/superpom/pom.xml</relativePath>
</parent>

这样你就可以只在一个 pom 文件中包含存储库部分,这就是你的超级 pom。您还可以在此处添加所有项目共有的任何依赖项,例如 junit、log4j 等。

在您的 settings.xml 文件中。您可以添加它来配置您的本地存储库。

<localRepository>C:/myBox/maven.repo</localRepository>

Add the repository section to the super pom. And let all the projects extend from the super pom.

So every other project pom will have a parent section to extend from the super pom like this.

<parent>
    <groupId>com.ddd.ddd.ddd</groupId>
    <artifactId>ddd-ddd-parent</artifactId>
    <version>1.1.1-SNAPSHOT</version>
    <relativePath>./config/superpom/pom.xml</relativePath>
</parent>

This way you can have the repository section only in one pom file, thats your super pom. You can also add any dependencies that are common to all the projects in here, like junit, log4j and stuff like that.

In your settings.xml file. You can add this to configure your local repository.

<localRepository>C:/myBox/maven.repo</localRepository>
百合的盛世恋 2024-10-24 04:16:01

settings.xml 中删除镜像设置并放置以下代码对我有用。

<profiles>
    <profile>
        <id>profile-1</id>
        <repositories>
            <repository>
                <id>internal-repository-1</id>
                <url>http://build.idaho.local/wtp_repository</url>
            </repository>
        </repositories>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>profile-1</activeProfile>
</activeProfiles>

Removing mirror settings from settings.xml and put following code worked for me.

<profiles>
    <profile>
        <id>profile-1</id>
        <repositories>
            <repository>
                <id>internal-repository-1</id>
                <url>http://build.idaho.local/wtp_repository</url>
            </repository>
        </repositories>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>profile-1</activeProfile>
</activeProfiles>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文