如何指定maven的分布管理组织范围?
我试图弄清楚如何组织许多(大约 50 多个)maven2 项目,以便它们可以部署到中央 Nexus 存储库中。使用 mvn deploy
目标时,确实需要在 distributionManagement 标记中指定目标,如下所示:
<distributionManagement>
<repository>
<id>nexus-site</id>
<url>http://central_nexus/server</url>
</repository>
</distributionManagement>
现在,我不希望每个 pom.xml(其中 50 多个)都包含此块反复。我的第一个文件是 settings.xml
文件,但似乎不可能(根据设计)在那里定义它。 那么,第一个问题是,为什么会出现这种情况?如果可能的话,我可以在 maven2 发行版的 settings.xml 中指定它,该发行版可以分发给所有开发人员。
我发现的唯一可能的解决方案是创建一个组织范围的 master-pom 项目,其中包含这些设置,并通过
使所有其他 pom.xml 依赖于此 master-pom > 标签。但这在多模块构建中看起来有点奇怪:
- master configuration POM (pm)
- Project 1 parent pom (p1 with module 1 and module 2 as modules)
- Project 1 module pom (with pm as parent)
- Project 2 module pom (with pm as parent)
通常我在所有文档中都读到模块 poms 应该使用父 pom,而不是其他的 pom。但是在阅读了有关 Inheritance v. Aggregation 的 Maven 网站后,它写道,这确实是可能的。
我发现的一个问题是 Maven 站点生成,该设置似乎确实存在问题(如果模块没有直接反向引用,则模块无法正确链接)
那么,这是一种有效的方法吗?还有其他更明显、更简单的问题解决方案吗?
I'm trying to figure out how to organize many (around 50+) maven2 projects, so that they can deploy into a central nexus repository. When using the mvn deploy
goal, one does need to specify the target in the distributionManagement tag like this:
<distributionManagement>
<repository>
<id>nexus-site</id>
<url>http://central_nexus/server</url>
</repository>
</distributionManagement>
Now, i don't want every single pom.xml (of those 50+) to contain this block over and over again. My first though would be the settings.xml
file, but it seems it is not possible (by design) to define it there.
So, the first question would be, why is that the case ? If it would be possible i could specify it in the settings.xml in the maven2 distribution, which could be distributed to all developers.
The only possible solution i've found was to create an organisation-wide master-pom project, that does contain these settings, and make all other pom.xml depend on this master-pom via <parent>
tag. But this looks kind of strange in multi-module builds:
- master configuration POM (pm)
- Project 1 parent pom (p1 with module 1 and module 2 as modules)
- Project 1 module pom (with pm as parent)
- Project 2 module pom (with pm as parent)
Usually i read in all documentation that the module poms should use the parent pom, not some different one. But after reading the maven website about Inheritance v. Aggregation it is written that it is indeed possible.
One problem i found was with the maven site generation, which does seem to have problems with this setup (modules does not get linked correctly if they have no direct back-reference)
So, is this a valid approach ? Any other, more obvious, simpler solution to the problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对此的最佳解决方案是为您组织中的所有项目创建一个简单的父 pom 文件项目(带有打包“pom”)。
可以构建、发布并将其部署到本地连接,以便每个人都可以访问其工件。
现在,对于您希望使用它的所有项目,只需包含此部分:
此解决方案将允许您轻松地将其他常见内容添加到公司的所有项目中。例如,如果您想将 JUnit 使用标准化为特定版本,那么这将是完美的地方。
如果您的项目使用具有自己的父级的多模块结构,Maven 还支持链式继承,因此完全可以接受让您的项目的父级 pom 文件引用您公司的父级 pom,并且让项目的子模块甚至不知道您的父级 pom 文件。公司的母公司。
我从您的示例项目结构中看到,您正在尝试将父项目与聚合器 pom.xml 置于同一级别。如果您的项目需要自己的父级,我发现的最佳方法是将父级包含在与其余模块相同的级别,并将聚合器 pom.xml 文件放在所有模块目录所在的根目录中。
您使用此结构所做的是将您的父模块包含在聚合器中,并使用
mvn install
从根目录构建所有内容。我们在我的组织中使用了这个精确的解决方案,它经受住了时间的考验,并且对我们来说效果很好。
The best solution for this is to create a simple parent pom file project (with packaging 'pom') generically for all projects from your organization.
This can be built, released, and deployed to your local nexus so everyone has access to its artifact.
Now for all projects which you wish to use it, simply include this section:
This solution will allow you to easily add other common things to all your company's projects. For instance if you wanted to standardize your JUnit usage to a specific version, this would be the perfect place for that.
If you have projects that use multi-module structures that have their own parent, Maven also supports chaining inheritance so it is perfectly acceptable to make your project's parent pom file refer to your company's parent pom and have the project's child modules not even aware of your company's parent.
I see from your example project structure that you are attempting to put your parent project at the same level as your aggregator pom. If your project needs its own parent, the best approach I have found is to include the parent at the same level as the rest of the modules and have your aggregator pom.xml file at the root of where all your modules' directories exist.
What you do with this structure is include your parent module in the aggregator and build everything with a
mvn install
from the root directory.We use this exact solution at my organization and it has stood the test of time and worked quite well for us.
不需要父 POM。
您可以在 poms 中完全省略 distributionManagement 部分,并将其设置在构建服务器上或在 settings.xml 中。
要在构建服务器上执行此操作,只需传递到
mvn
命令:请参阅 https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html 了解可以设置哪些选项的详细信息。
也可以在
settings.xml
中进行设置。只需在其中创建一个启用并包含该属性的配置文件即可。
示例 settings.xml:
确保“snapshots”和“releases”的凭据位于 settings.xml 的
部分中属性 altSnapshotDeploymentRepository 和 altReleaseDeploymentRepository 是通过 maven-deploy-plugin 引入的2.8 版。旧版本将失败并显示错误消息
要解决此问题,您可以强制使用较新版本的插件:
There's no need for a parent POM.
You can omit the distributionManagement part entirely in your poms and set it either on your build server or in settings.xml.
To do it on the build server, just pass to the
mvn
command:See https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html for details which options can be set.
It's also possible to set this in your
settings.xml
.Just create a profile there which is enabled and contains the property.
Example settings.xml:
Make sure that credentials for "snapshots" and "releases" are in the
<servers>
section of your settings.xmlThe properties altSnapshotDeploymentRepository and altReleaseDeploymentRepository are introduced with maven-deploy-plugin version 2.8. Older versions will fail with the error message
To fix this, you can enforce a newer version of the plug-in:
关于 Michael Wyraz 的答案,您在
中使用
或者命令行,在 maven-deploy-plugin 3.0.0 版本中格式发生了变化,alt*DeploymentRepository
参数settings.xml在 value 中:
需要删除
default
部分,使其:Regarding the answer from Michael Wyraz, where you use
alt*DeploymentRepository
parameters in yoursettings.xml
or command line, the format has changed in version 3.0.0 of the maven-deploy-pluginIn the value:
you need to remove the
default
section, making it: