2024年java deploy到新版本maven公共仓库的方法

1,177 阅读2分钟

[前言] 之前写过若干java开发时简化操作或者是拓展功能的工具包,因为懒好久没更新了。最近因为个别项目里面使用时出现应用场景不太够就更新了一波。本打算立刻发布到maven的中心库中以便引入,突然发现发不上去了!于是有了以下调查内容。

背景

发布时出现401错误

Remote staging finished with a failure: Failed to deploy artifacts: Could not transfer artifact cn.allbs:allbs-influx:jar:javadoc:2.1.0 from/to sonatype-nexus-snapshots (s01.oss.sonatype.org:443/service/loc…): status code: 401, reason phrase: Content access is protected by token (401)

image.png image.png

登录仓库查看

仓库中缺少很多包的信息,只有很久没更新过的包残存在上面。 image.png

管理端查看

image.png 查了一下自己仓库,发现包其实是上传上来了,但是关闭并发布是不起效果的。考虑了一下可能又换仓库了,想起官方访问页面之前是变了样式得,也和这种可能性相和。这样得话只能去官方找资料查看了。 image.png

开始解决

官网上的说明文档

链接如下: central.sonatype.org/faq/what-is…

image.png

大致可以看出旧版和新版并不兼容,同时旧版的命名空间并不能带入到新版之中,如果要迁移必须写邮件申请。

开始转移namespace

注意这些操作全是基于你在旧版上注册过!以下邮件的红色内容需要替换为你自己实际信息,不要照抄。 image.png

  • 主题:Request for Namespace Migration to OSSRH
  • 邮件接收方:central-support@sonatype.com
  • 内容参考:
Dear Central Support Team,

I am writing to request the migration of my namespace from OSSRH to the Central Portal. Below are the details of my account and the namespace I wish to migrate:

- **Account Information:**
    
    - Username: [你的旧版账号]
    - Email: [账号绑定的邮箱]
- **Namespace(s) to Migrate:**
    
    - 你的namespace

The reason for this migration request is to facilitate the version iteration and maintenance of our existing functionality packages. We believe that migrating to OSSRH's Central Portal will provide better management capabilities and access to new features that will enhance our development and deployment processes.

I appreciate your assistance with this request and look forward to your response. Please let me know if any additional information is required.

Thank you.

Best regards,  
[你的姓名]  
[你的联系方式]

没几分钟就能收到对方的回复邮件,大概意思是已经接受处理,需要等待,如果有补充继续发给他们。 image.png

修改deploy至新库

首先是获取userToken

新的maven公共库和以前的方式不同,deploy需要发布的用户名和token

修改maven的setting.xml

java的pom.xml中的修改

主要是两处地方 一是: image.png

第二处: image.png

执行deploy看看效果

能推入库中说明以上配置已经生效了,但是因为namespace还未从旧版移过来所以发布失败了。下面只需要安心等待即可。 image.png