🏷️ 标签:#maven #经验分享 #java #mavenplugin #maven中央仓库
📚背景
OSSRH服务于250630服务结束,无法再使用原nexus-staging-maven-plugin插件配置直接上传到中央仓库,影响release和快照版deploy。
影响的相关仓库地址有:
访问首页后可见:
The OSSRH service will reach end-of-life on June 30th, 2025. Learn more about how to transfer to the Central Publishing Portal here.
对应说明链接:
central.sonatype.org/pages/ossrh…
💡 前言
本文作者 “新程快咖员” ,转载请注明出处~
原文地址 -> [戳这里]
官方下线了原有的服务,无法再通过原有nexus-staging-maven-plugin插件直接进行发布。博主也遇到了这个问题,就进行了梳理,让我带你快速切换 ~
一种是(方式1)切换nexus-staging-maven-plugin插件为central-publishing-maven-plugin插件,一种是(方式2)保持原有插件不变只进行替换token和相关url即可( 发布release成功后会部署记录会包含(via OSSRH Staging API)标识 )。
注:方式1和方式2按需使用即可,同一分支代码只保留一种,下文出现方式1和方式2关键字时需留意。
插件推荐:
💥 IDEA 神器 Maven With Me(MPVP) 插件,Maven 开发加速必备!
一键轻松帮您搞定版本值升级或回退(再也不用头疼和花费大量时间调整版本值啦)
支持项目视图中展示版本值,一眼便能知晓当下版本~
支持查询中央仓库最新依赖版本,也可以快速查询Nexus仓库(远程/私服)依赖版本~
详情直达 -> 戳这里
🌟 操作步骤
1、登录网站
用户名、密码和原OSSRH服务网站一致
2、启用快照版
点击头像,选择View Namespaces菜单。也可直接访问下面的链接:
central.sonatype.com/publishing/…
找到已有的Central Portal Namespaces,点击最右边的按钮,选择Enable SNAPSHOTs即可
3、获取发布token并修改setting.xml
点击头像,选择View Account菜单。也可直接访问下面的链接:
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
然后点击Generate User Token按钮进行操作(弹窗后选择OK)即可得到最新发布需要的Username和Password。
方式1:切换为新central-publishing-maven-plugin插件? (重要!!!)
在当前使用的 maven 所生效的setting.xml 找到 标签新增 配置即可 (这里id使用central,username和password进行替换上面获取的数据)。
<server>
<id>central</id>
<username></username>
<password></password>
</server>
方式2:仍使用原插件nexus-staging-maven-plugin? (重要!!!)
在当前使用的 maven 所生效的setting.xml 找到 原ossrh的 配置进行替换即可 (这里id保持原有不变,username和password进行替换上面获取的数据)。
<server>
<id>ossrh</id>
<username></username>
<password></password>
</server>
4、修改pom.xml
4.1 修改插件配置
方式1:切换为新central-publishing-maven-plugin插件? (重要!!!)
注释或删除原有nexus-staging-maven-plugin(包含属性配置):
<!-- <plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>${nexus-staging-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
-->
新增插件配置:
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.8.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<autoPublish>true</autoPublish>
<!--
<waitUntil>published</waitUntil>
-->
</configuration>
</plugin>
方式2:仍使用原插件nexus-staging-maven-plugin? (重要!!!)
修改标签值为新url
<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>
-->
<!--
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
-->
<nexusUrl>https://ossrh-staging-api.central.sonatype.com/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
4.2 标签进行调整配置
方式1:切换为新central-publishing-maven-plugin插件? (重要!!!)
进行注释或删除原有ossrh的 snapshotRepository 和 repository配置,新增central的snapshotRepository配置
当前采用注释的方式进行处理,如下所示:
<distributionManagement>
<!-- <snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
-->
<!-- https://central.sonatype.org/publish/publish-portal-snapshots/ -->
<snapshotRepository>
<id>central</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
方式2:仍使用原插件nexus-staging-maven-plugin? (重要!!!)
替换snapshotRepository的url为新url,替换repository的url为新url
如下所示:
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<!--
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
-->
<!--
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
-->
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<!--
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
-->
<!--
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
-->
<url>https://ossrh-staging-api.central.sonatype.com/service/local/</url>
</repository>
</distributionManagement>
4.3 (可选) 标签新增Central Portal Snapshots repository用于加载依赖
<repositories>
<repository>
<name>Central Portal Snapshots</name>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
5、deploy
正常deploy即可
其他
如何获取最新快照版本(img.shields.io)徽章?
这里可以访问 shields.io/badges/mave… 进行生成,主要参数就是 metadataUrl 和 label (自定义,一般为latest snapshot)。
metadataUrl即依赖的 maven-metadata.xml 地址 (可从deploy的快照版maven-metadata.xml地址进行复制,不包含快照版本名称的路径),格式如下:
https://central.sonatype.com/repository/maven-snapshots/ + {groupId中的.替换为/} + / + {artifactId} + /maven-metadata.xml
官方文档
生成token:
central.sonatype.org/publish/gen…
通过maven发布:
central.sonatype.org/publish/pub…
发布快照版:
central.sonatype.org/publish/pub…
Publishing By Using the Portal OSSRH Staging API:
central.sonatype.org/publish/pub…
🎉 结尾
欢迎关注公众号 “新程快咖员” 解锁更多内容!
以上就是本篇文章的全部内容啦,感谢您的阅读和观看。欢迎点赞、转发(分享)和推荐~