设置Maven以允许轻松地部署到不同的存储库 [英] Setting up Maven to allow deployment to different repositories easily
问题描述
我目前正在为许多人定义规则的环境中工作.目前,我们使用的是Hudson和Artifactory,我想评估一下转向Jenkins和Nexus是否值得进行迁移(但这不是问题).
I'm currently working in an environment where I define the rules for a lot of people. We currently use Hudson and Artifactory, and I want to evaluate if the switch to Jenkins and Nexus are worth the migration cost (but this is not the question).
要评估它,我在本地设置了Maven,Jenkins和Nexus,并且我尝试找到一个可以使用以前的大部分设置的设置,以便我可以比较解决方案.这里的问题是:
To eval it, I have setup Maven, Jenkins, and Nexus locally, and I try to find a setup to use as much of the previous setup, so that I can compare the solutions. The problem here is:
- 当我使用现有的POM并通过Jenkins构建和部署它时,它会自动部署到我们的旧环境中.
-
然后我尝试在Maven的
.settings
文件中定义deploymentManagement
部分,但这是不允许的(请参阅
- When I use an existing POM and build and deploy it through Jenkins, it is automatically deployed to our old environment.
I have then tried to define the
deploymentManagement
section in my.settings
file in Maven, but this is not allowed (see Configuring Maven, there
注意:安装和用户配置不能用于添加共享的项目信息,例如设置或公司范围内的信息.
Note: the installation and user configuration cannot be used to add shared project information - for example, setting or company-wide.
我们当前的根POM包含以下部分:
Our current root POM contains the following section:
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>company-central</id>
<name>Company central maven respository</name>
<url>https://company.com/artifactory/libs-releases</url>
</repository>
<snapshotRepository>
<id>company-snaps</id>
<name>company-snapshots</name>
<url>https://company.com/artifactory/libs-snapshots</url>
</snapshotRepository>
<downloadUrl>https://company.com/artifactory/libs-releases</downloadUrl>
</distributionManagement>
使用相同的POM并将其部署到不同的存储库管理器的最简单方法是什么?
What is the easiest way to use the same POM, but to deploy it to different repository managers?
PS:我已阅读设置maven pom文件用于不同的部署方案,并且不喜欢(在我的上下文中),在maven中进行多个部署是一种有趣的方法,但是我只需要修改很多POM为此目的.
PS: I have read set up maven pom file for different deployment scenarios and don't like it (in my context), Deploying Maven artifact to multiple repositories with different settings is really a different question. Multiple deployments in maven is an interesting approach, but I would have to modify a lot of POMs only for this purpose.
推荐答案
我在一个类似的团队中,为其他人提供工具.我们的父POM (不是settings.xml
)设置如下.除非我的团队成员之一在mvn命令行中添加-DuseTestRepo=true
,否则该prod版本将处于活动状态.您可以尝试更改激活以查找仅在Jenkins服务器上存在的特定文件(例如).我也想知道Maven是否在回购URL中插入属性.如果是这样,您可以执行<url>${my.remote.repo}/releases</url>
并在settings.xml中定义my.remote.repo
.还没尝试过那个.
I'm on a similar team, providing tools to others. We have our parent POM (not the settings.xml
) set up like the below. The prod version is active unless one of my team members adds -DuseTestRepo=true
to the mvn command line. You could experiment with changing the activation to look for a particular file that exists only on the Jenkins server (for example). I've also wondered if Maven interpolates properties in repo URLs. If it does, you could do <url>${my.remote.repo}/releases</url>
and define my.remote.repo
in settings.xml. Haven't tried that one.
<profiles>
<profile>
<id>test-repository</id>
<activation>
<property>
<name>useTestRepo</name>
<value>true</value>
</property>
</activation>
<properties>
</properties>
<distributionManagement>
<repository>
<!-- ... -->
</repository>
<snapshotRepository>
<!-- ... -->
</snapshotRepository>
</distributionManagement>
</profile>
<profile>
<id>prod-repository</id>
<activation>
<property>
<name>!useTestRepo</name>
</property>
</activation>
<properties>
</properties>
<distributionManagement>
<repository>
<!-- ... -->
</repository>
<snapshotRepository>
<!-- ... -->
</snapshotRepository>
</distributionManagement>
</profile>
关于交付(部署)实验性父POM,您将其部署到测试Nexus仓库中,对吗?而且您的开发人员都没有访问权限,只有您自己.因此,Artifactory将包含真实的com.company:corporate-parent:1.0
POM,而Nexus将包含包含您进行测试所需的更改的com.company:corporate-parent:1.0
.
As to delivering (deploying) your experimental parent POM - you would be deploying it to your test Nexus repo, right? And none of your developers are accessing that, only you. So Artifactory will contain the real com.company:corporate-parent:1.0
POM, and Nexus the com.company:corporate-parent:1.0
that contains the changes you require for your testing.
我还将考虑在您的settings.xml中更改本地存储库,这样您就不会混合来自两个远程存储库的工件.
I would also consider changing the local repo in your settings.xml so you don't mix artifacts from the two remote repos.
这篇关于设置Maven以允许轻松地部署到不同的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!