【发布时间】:2020-07-22 23:19:04
【问题描述】:
我有公司的 Maven 存储库。我有公司超级pom.xml 部分<repository> 和<pluginRepository> 指向公司回购。公司超级pom分离神器。
我开发我的 Maven 项目。父pom是公司超级pom。为了在干净的环境中通过构建,我需要在我的项目主页中再次定义 <repository>,因为 Maven 必须知道可以找到父 pom 的位置(请参阅 Catch-22)
我很不高兴在我的项目中再次定义了公司存储库,但我接受了它。
在我的项目中,我使用公司插件。问题是 Maven 找不到公司插件。这很奇怪,因为 maven 找到了带有<pluginRepository> 的超级 pom 但不使用插件存储库来查找插件!所以我要再次定义<pluginRepository>
超级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,则不需要 <pluginRepositories>。
Maven 3.3.3
更新:
如果我从项目 pom 中删除 <pluginRepositories>,则 Effective-pom 不会将 company-repo 显示为插件存储库。我希望。
【问题讨论】:
-
最好通过
settings.xml文件代替。 -
我发现
settings.xml有两个问题。 1 - 构建不可移植 2 - 我需要在<profiles>部分中定义<pluginRepositories>当我在构建中选择一些配置文件时,我的意思是:这个构建具有其他构建不使用的特定内容。但是所有构建都需要插件存储库,因此不应将其配置为配置文件。比较:每天早上我决定穿长裤或短裤。那是简介。但不管裤子我穿裤子。裤子不是廓形。插件库是裤子。不是个人资料。 -
你应该在 settings.xml 中配置一个镜像,就是这样......什么是不可移植的?您使用存储库管理器吗?而且配置文件没有意义......
-
Portable 意味着您只需要从 repo 中检查并调用 mvn install。 不可移植 意味着构建需要额外的工作 - 在此处编辑 settings.xml。无论如何,我现在很清楚您建议在 settings.xml 中配置
<mirrors>部分。听起来很合理。请感到鼓励撰写完整的答案 -
父POM中声明的插件仓库是否出现在
mvn help:effective-pom的输出中?
标签: maven