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