[英]Simultaneously deploy artifact to Maven Central and internal Nexus
我有一个项目,它使用 Maven release
和nexus-staging-maven
插件通过 OSSRH 部署到 Maven Central,使用来自http://central.sonatype.org/pages/ossrh-guide.html和http://central的指示。 sonatype.org/pages/apache-maven.html 。
这工作正常,但通常需要几个小时才能在 Maven Central 上看到工件。 通常我们希望立即使用已部署的工件,因此我们最终使用deploy:deploy-file
将其从本地存储库部署到我们的内部 Nexus 服务器。 这有效,但它不优雅且容易忘记。 有什么方法可以让 Maven 部署到内部 Nexus 以及 Maven Central 作为发布过程的一部分?
注意:这个问题与https://stackoverflow.com/questions/29019682/promote-artifact-from-internal-nexus-repository-to-maven-central类似,但不完全相同
向maven-deploy-plugin
添加一个附加执行:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.plugin.version}</version>
<executions>
<execution>
<id>nexus-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<altDeploymentRepository>yourNexusRepo</altDeploymentRepository>
</configuration>
</execution>
</executions>
</plugin>
yourNexusRepo值将如下所示:
releases::default::https://nexus.host.org/nexus/content/repositories/releases
您应该能够从Nexus获取确切的网址。 第一个::之前的部分是存储库ID。
我们不再使用nexus-staging-maven-plugin
作为扩展来解决这个问题。 这在https://help.sonatype.com/repomanager2/staging-releases/configuring-your-project-for-deployment 中有描述:
如果需要对插件部署目标何时激活或使用 Maven 2 进行更多控制,则必须明确停用 Maven Deploy 插件并将 Maven Deploy 插件调用替换为 Nexus Staging Maven 插件...
在我们的例子中,我们通过设置<phase>none</phase>
禁用default-deploy
执行。 我们的完整解决方案可在https://github.com/newmediaworks/nmw-oss-parent/commit/a7377a158feded473cb2f1618449e34173c22252获得,其中包括在jenkins-deploy
配置文件中额外执行maven-deploy-plugin
。
关键要点如下,到目前为止,它似乎表现得好像启用了扩展,但不会干扰额外的maven-deploy-plugin
执行:
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId>
<!--
Not using as extension, since it blocks maven-deploy-plugin in the jenkins-deploy profile:
<extensions>true</extensions>
-->
<executions>
<execution>
<!-- Manually added since nexus-staging-maven-plugin is not used as extension -->
<id>default-deploy</id><phase>deploy</phase><goals><goal>deploy</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId><artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<!-- Manually disabled since nexus-staging-maven-plugin is not used as extension -->
<id>default-deploy</id><phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.