简体   繁体   English

将Maven工件部署到具有不同设置的多个存储库

[英]Deploying Maven artifact to multiple repositories with different settings

We have numerous Java projects, which are CI built with Jenkins. 我们有许多Java项目,它们是使用Jenkins构建的CI。 These are deployed to our own Nexus server just fine. 这些部署到我们自己的Nexus服务器就好了。 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: 因此,对于每个项目,在Nexus中我们有:

  • 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) 第三方发布存储库(仅限JAR + POM)
  • (and would be good to have): Third party snapshot repository (only JAR + POM) for third party nightly builds (并且很高兴): 第三方快照存储库(仅限JAR + POM)用于第三方夜间构建

The question is: how is this usually handled in Jenkins/Nexus world? 问题是:在Jenkins / Nexus世界中,这通常是如何处理的? I'd prefer to have one single Job in Jenkins which handles the CI build and the release (artefact deployment) process "automatically". 我宁愿在Jenkins中有一个单独的Job,它可以“自动”处理CI构建和发布(artefact部署)过程。 Currently I'm using multiple <distributionManagement> profiles in our "main root pom.xml" (included by all projects): 目前我在“main root pom.xml”中使用了多个<distributionManagement>配置文件(包含在所有项目中):

[...]
<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>

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. 在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. 我可以通过使用Maven“目标和选项”在Jenkins中创建Job来完成一个技巧: clean deploy -P third-party ,然后使用“默认”数据添加Post-build操作 - “将工件部署到Maven存储库” - 但在这种情况下,只有SNAPSHOT会同时通过Jenkins Maven Release Plug-in发布的repo和artefacts只进入一个存储库。

Any practical ideas how can I do this without overcomplicating our CI job hierarchy? 任何实用的想法如何在不过度复杂CI作业层次结构的情况下实现这一目标?

Thanks in advance! 提前致谢!

You can just handle this all in Nexus. 你可以在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. 创建一个存储库目标,其中包含类似于预配置示例“All but sources(Maven 2)”中使用的模式,并使用另一个限制groupid,artifactid甚至版本的模式进一步缩小目标。

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.. 无需进行多次部署或某些此类..

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

您可以使用Maven Wagon插件并在部署阶段将单个jar上传到远程位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM