【问题标题】:<pluginRepository> in parent pom is ignored when parent pom is accessed through repository当通过存储库访问父 pom 时,忽略父 pom 中的 <pluginRepository>
【发布时间】:2020-07-22 23:19:04
【问题描述】:

我有公司的 Maven 存储库。我有公司超级pom.xml 部分&lt;repository&gt;&lt;pluginRepository&gt; 指向公司回购。公司超级pom分离神器。

我开发我的 Maven 项目。父pom是公司超级pom。为了在干净的环境中通过构建,我需要在我的项目主页中再次定义 &lt;repository&gt;,因为 Maven 必须知道可以找到父 pom 的位置(请参阅 Catch-22

我很不高兴在我的项目中再次定义了公司存储库,但我接受了它。

在我的项目中,我使用公司插件。问题是 Maven 找不到公司插件。这很奇怪,因为 maven 找到了带有&lt;pluginRepository&gt; 的超级 pom 但不使用插件存储库来查找插件!所以我要再次定义&lt;pluginRepository&gt;

超级pom:

<repositories>
    <repository>
        <id>company-repo</id>
        <url>http://mycompany.com/repo</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>company-repo</id>
        <url>http://mycompany.com/repo</url>
    </pluginRepository>
</pluginRepositories>

我的项目 pom:

<!-- required to find company super pom - unhappy but accepted-->
<repositories>
    <repository>
        <id>company-repo</id>
        <url>http://mycompany.com/repo</url>
    </repository>
</repositories>
<!-- required to find company plugin - unhappy and hard to accept-->
<pluginRepositories>
    <pluginRepository>
        <id>company-repo</id>
        <url>http://mycompany.com/repo</url>
    </pluginRepository>
</pluginRepositories>

问题:是否可以避免在每个 Maven 项目中重复插件存储库配置?也许我应该改变我的设计/配置/什么?

有趣的是,如果通过相对路径而不是通过存储库访问超级 pom,则不需要 &lt;pluginRepositories&gt;

Maven 3.3.3

更新:

如果我从项目 pom 中删除 &lt;pluginRepositories&gt;,则 Effective-pom 不会将 company-repo 显示为插件存储库。我希望。

【问题讨论】:

  • 最好通过settings.xml文件代替。
  • 我发现settings.xml 有两个问题。 1 - 构建不可移植 2 - 我需要在 &lt;profiles&gt; 部分中定义 &lt;pluginRepositories&gt; 当我在构建中选择一些配置文件时,我的意思是:这个构建具有其他构建不使用的特定内容。但是所有构建都需要插件存储库,因此不应将其配置为配置文件。比较:每天早上我决定穿长裤或短裤。那是简介。但不管裤子我穿裤子。裤子不是廓形。插件库是裤子。不是个人资料。
  • 你应该在 settings.xml 中配置一个镜像,就是这样......什么是不可移植的?您使用存储库管理器吗?而且配置文件没有意义......
  • Portable 意味着您只需要从 repo 中检查并调用 mvn install。 不可移植 意味着构建需要额外的工作 - 在此处编辑 settings.xml。无论如何,我现在很清楚您建议在 settings.xml 中配置&lt;mirrors&gt; 部分。听起来很合理。请感到鼓励撰写完整的答案
  • 父POM中声明的插件仓库是否出现在mvn help:effective-pom的输出中?

标签: maven


【解决方案1】:

最简单的方法是setup your settings.xml file like this:

<settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

使用存储库管理器让生活更轻松...除此之外,您当然可以使用single pom which could be made。但是开发人员无法更改使用父级,并且您无法更改 CI 解决方案(如 Jenkins)来配置其适当的settings.xml

【讨论】:

  • 仅限&lt;mirrors&gt;部分的解决方案怎么样?看起来是否足够:由于&lt;mirrorOf&gt;*&lt;/mirrorOf&gt; 任何下载请求都将由公司存储库处理。
  • 顺便说一句,你在评论中写的有点奇怪`配置文件没有意义......`但解决方案主要基于配置文件......
  • khmarbaise,请参阅我对 OP 的评论。我遇到了一些类似的问题,到目前为止我还无法归结为一个小例子并重现。知道这是一个错误还是什么会很有帮助。有什么想法吗?我之所以问,是因为我看到您回答了很多 Maven 问题,并且我在 Maven JIRA 和(我认为)发行说明中看到了您的名字。谢谢。
【解决方案2】:

虽然这是对这个问题的一个非常晚的答案,但我相信我遇到了同样的问题,这实际上不是 Maven 的问题。我们使用 Artifactory 作为工件的本地存储,它设置为在您下载 pom 时剥离存储库/插件存储库信息。可以在存储库的配置面板中禁用此行为。

https://www.jfrog.com/jira/browse/RTFACT-5343

我想您在使用 Artifactory 时遇到了同样的问题。

【讨论】:

    猜你喜欢
    • 2012-02-03
    • 2014-02-14
    • 2012-03-31
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2018-08-07
    相关资源
    最近更新 更多