在网上找的很多文章中写得都有很多问题,这里记录一下最近一次成功地发布jar包到maven中央仓库的过程。并附带上每一个步骤官方的指导链接。
官方对发布的项目做了一些必需的要求,如果不按要求来,发布可能会报错。2.1. javadoc和source
参考:https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources2.2. 使用 GPG/PGP 签署文件
参考:https://central.sonatype.org/publish/requirements/#sign-files-with-gpgpgp2.3. 项目名称和版本配置
参考:https://central.sonatype.org/publish/requirements/#correct-coordinates2.4. 项目名称、描述和 URL
参考:https://central.sonatype.org/publish/requirements/#project-name-description-and-url2.5. 许可证书
参考:https://central.sonatype.org/publish/requirements/#license-information2.6. 开发人员信息
参考:https://central.sonatype.org/publish/requirements/#developer-information2.7. SCM 源码管理系统信息
参考:https://central.sonatype.org/publish/requirements/#scm-information2.8. 文件签名校验(非必需)
参考:https://central.sonatype.org/publish/requirements/#provide-files-checksums3. 在 JIRA 上提发布申请
参考:https://central.sonatype.org/publish/publish-guide/#initial-setup3.2. 创建项目
在等待JIRA项目审核的同时,可以并行把GPG密钥搞定。4.1. 安装 GnuPG
注意:mac系统和windows系统在获取GPG密钥时有些区别,mac全程都是通过命令行搞定的,而windows提供了操作界面,可能会方便一点。这里只介绍mac系统的配置方式,windows系统可以自行搜配置教程。
参考:https://central.sonatype.org/publish/requirements/gpg/#installing-gnupg4.2. 生成密钥对
参考:https://central.sonatype.org/publish/requirements/gpg/#generating-a-key-pair4.3. 发布公钥
官网提供了3个地址,有的地址可能不能用,上面这个地址亲测有效。(所以官方也不一定靠谱)[img=30%,auto]https://img2023.cnblogs.com/blog/2706986/202312/2706986-20231211184153518-1763399774.jpg[/img]
参考:https://central.sonatype.org/publish/requirements/gpg/#distributing-your-public-key5. JIRA 项目核审通过后的配置
这里修改的是maven的setting.xml配置文件,如果不知道配置文件在哪里(那么你不是一个合格的程序猿),可以在IntelliJ IDEA的settings > Build,Execution,Deployment > Builds Tools > Maven页面找到User settings file。
这里是在项目的pom文件中配置。
JIRA 核审通过后,就可以发布了6.1. 发布到中央仓库
发布成功以后,并不能立刻在maven中央仓库中搜索到,大概隔一天以后才能搜索得到,所以不要心急,耐心等待。
一般是隔天,才能在中央仓库里搜得到,在阿里云的仓库里也可以搜得到,阿里云本来就是从中央仓库同步的。建议使用groupId来搜,一搜一个准。用artifactId来搜在第一页可能找不到,因为maven会对搜索结果做排序。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |