nexus-staging-maven-plugin 踩坑

來自:https://juejin.im/post/6844903561944367117

這貨是啥

nexus-staging-maven-plugin是一個nexus用來自動控制流程的客戶端插件。如果你想分享自己的java開源項目到maven中央倉庫,就有可能需要這個插件。

問題是啥

重現問題需要下面幾步,
第一步:
需要先在sonatype上發起一個新開源項目的issue等待審覈通過。
第二步:
修改自己的pom.xml,讓他符合maven中央倉庫的檢查規則。
幾個重要的規則是開發者信息

maven-javadoc-plugin //打包javadoc
maven-source-plugin //打包源碼
maven-gpg-plugin //gpg簽名驗證

複製代碼簽名需要自己生成,詳細教程在deploy-to-maven-central-repository
第四步:
nexus本身有一套發佈jar的流程,下面這個插件可以是nexus流程處理的客戶端.

<plugin>
    <groupId>org.sonatype.plugins</groupId>
    <artifactId>nexus-staging-maven-plugin</artifactId>
    <version>1.6.7</version>
    <extensions>true</extensions>
    <configuration>
        <serverId>ossrh</serverId>
        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
        <autoReleaseAfterClose>true</autoReleaseAfterClose>
    </configuration>
</plugin>

複製代碼好的,請記住這個插件,當你執行mvn deploy的時候,它會自己上傳當前maven工程下的所有模塊到nexus.
比如說xxx-service-api的實現,xxx-web.

怎麼解決

如果想把某個模塊忽略,需要增加配置

<plugin>
	<groupId>org.sonatype.plugins</groupId>
	<artifactId>nexus-staging-maven-plugin</artifactId>
	<configuration>
		<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
	</configuration>
</plugin>

複製代碼end.

懶人版

在用了nexus-staging-maven-plugin插件之後,下面的配置不能避免模塊被髮布到nexus

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-deploy-plugin</artifactId>
	<configuration>
		<skip>true</skip>
	</configuration>
</plugin>

複製代碼還需要增加

<plugin>
	<groupId>org.sonatype.plugins</groupId>
	<artifactId>nexus-staging-maven-plugin</artifactId>
	<configuration>
		<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
	</configuration>
</plugin>

總結:我按照上述方式配置發現,所有模塊都不上傳了,很奇怪,於是乎,一不做二不休,直接移除掉nexus-staging-maven-plugin,只使用maven-deploy-plugin,用手動的方式進行操作。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章