使用不同的设置将Maven工件部署到多个存储库 [英] Deploying Maven artifact to multiple repositories with different settings

查看:182
本文介绍了使用不同的设置将Maven工件部署到多个存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有许多Java项目,它们是使用Jenkins构建的CI。这些部署到我们自己的Nexus服务器就好了。
问题是,我们需要将这些库提供给第三方,但没有源代码。
因此对于每个项目,在Nexus中我们有:

We have numerous Java projects, which are CI built with Jenkins. These are deployed to our own Nexus server just fine. The problem is, we need to provide these libraries to a third party, but without the source code. So for each project, in Nexus we have:


  • 发布我们开发人员的存储库(包括已部署源代码)

  • 我们开发人员的快照存储库(包括已部署的源代码)

  • 第三方发布存储库(仅限JAR + POM)

  • (并且很好):第三方快照存储库(仅限JAR + POM)用于第三方派对每夜构建

  • Releases repository for our devs (includes deployed source code)
  • Snapshots repositories for our devs (includes deployed source code)
  • Third party release repository (only JAR + POM)
  • (and would be good to have): Third party snapshot repository (only JAR + POM) for third party nightly builds

问题是:这在Jenkins / Nexus世界中通常如何处理?我宁愿在Jenkins中有一个单独的Job,它可以自动处理CI构建和发布(artefact部署)过程。
目前我在main root pom.xml中使用了多个< distributionManagement> 配置文件(包含在所有项目中):

The question is: how is this usually handled in Jenkins/Nexus world? I'd prefer to have one single Job in Jenkins which handles the CI build and the release (artefact deployment) process "automatically". Currently I'm using multiple <distributionManagement> profiles in our "main root pom.xml" (included by all projects):

[...]
<profiles>
    <profile>
        <id>default</id>
        <distributionManagement>
            <repository>
                <id>releases</id>
                <name>Release</name>
                <url>http://path/to/nexus/content/repositories/releases/</url>
            </repository>
            <snapshotRepository>
                <id>snapshots</id>
                <name>Snapshot</name>
                <url>http://path/to/nexus/content/repositories/snapshots/</url>
                <uniqueVersion>false</uniqueVersion>
            </snapshotRepository>
        </distributionManagement>
    </profile>
    <profile>
        <id>third-party</id>
        <distributionManagement>
            <repository>
                <id>releases</id>
                <name>Release</name>
                <url>http://path/to/nexus/content/repositories/third-party/</url>
            </repository>
            <snapshotRepository>
                <id>snapshots</id>
                <name>Snapshot</name>
                <url>http://path/to/nexus/content/repositories/third-party-snapshots/</url>
                <uniqueVersion>false</uniqueVersion>
            </snapshotRepository>
        </distributionManagement>
    </profile>
</profiles>

从Maven文档中,似乎无法在同一构建生命周期中使用多个存储库,更不用说我们需要/不需要基于目标仓库的源。

From the Maven docs, it seems to be no way of using multiple repositories during the same build lifecycle, not to mention the fact that we need/don't need the source based on the target repo.

我可以在Jenkins中创建一个Job,然后使用Maven目标和选项:清除部署-P第三方,然后使用默认数据添加构建后操作 - 将工件部署到Maven存储库 - 但是在这种情况下,只有SNAPSHOT会通过 Jenkins Maven发布插件仅进入一个存储库。

I can do a trick with creating a Job in Jenkins, with the Maven "Goals and options": clean deploy -P third-party and then adding the Post-build action - "Deploy artifacts to Maven repository" with the "default" data - but in this case, only SNAPSHOTs are going to both repo and artefacts released via Jenkins Maven Release Plug-in are going into one repository only.

任何实用的想法如何在不过度复杂的情况下执行此操作我们的CI工作层级?

Any practical ideas how can I do this without overcomplicating our CI job hierarchy?

提前致谢!

推荐答案

你可以在Nexus中处理这一切。创建一个存储库目标,其中包含类似于预配置示例All but sources(Maven 2)中使用的模式,并使用另一个限制groupid,artifactid甚至版本的模式进一步缩小目标。

You can just handle this all in Nexus. Create a repository target that contains a pattern like the one used in the preconfigured example "All but sources (Maven 2)" and narrow that target down even further with another pattern that restricts the groupid, artifactid and maybe even version.

然后创建一个使用该存储库目标的权限,并将其分配给您希望具有相应访问权限的用户或角色。

Then create a privilege that uses that repository target and assign it to the user or role you want to have the respective access.

无需进行多次部署或某些此类..

No need to do multiple deployments or some such..

请参阅 http://books.sonatype.com/nexus-book/reference/repository-targets.html

这篇关于使用不同的设置将Maven工件部署到多个存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆