在平台用邮箱注册,后面步骤依赖这个邮箱接收最新回复、问题进展
Sign up for Jira - Sonatype JIRA
a.步骤如下图123,勾选配置域,不清楚就无脑全勾上,附件不用勾。

b.填充问题表单,签名项目及类型,保持如下图一致即可,填写后面的带*选项

c. 填写:groupId可以是自己拥有的域名,可以是GitHub,这里举例GitHub。
其中,【yourname】 要替换成你自己的GitHub用户名

d. 创建完毕后,会有专人跟进,留意时差对方是否在上班时间,可以关注自己注册的邮箱,有进度、回复,会邮件提醒到。

e. 按要求,做验证操作

总的就是三个步骤:安装GPG、生成key、创建secretKeyRingFile
命令行窗口安装gpg ,window安装可以参考:Android库发布至MavenCentral流程详解_GitLqr的博客-CSDN博客
mac 未安装 homebrew ,是无法使用brew 命令的,可以参考教程:MacOS安装和使用Homebrew图文详解_Cupster的博客-CSDN博客_mac安装brew
- brew install gpg
- // 如果中途遇到某个库安装失败,就执行 brew install xxx,单独安装它,然后再重新执行 brew install gpg

安装成功执行 【gpg --version】会有版本信息
gpg --version

- gpg --full-gen-key
- # 需要记住输入的密码,后面发布aar需要配置到 signing.password
中间会有询问key 类型,都选择默认【default】即可,最后记得保存好生成的信息,将来会用到。

- GnuPG needs to construct a user ID to identify your key.
-
- Real name: orixxxx
- Email address: orixxxxx@163.com
- Comment: orixxxx
- You selected this USER-ID:
- "orixxxxx (orixxxx)
" -
- Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
- We need to generate a lot of random bytes. It is a good idea to perform
- some other action (type on the keyboard, move the mouse, utilize the
- disks) during the prime generation; this gives the random number
- generator a better chance to gain enough entropy.
- We need to generate a lot of random bytes. It is a good idea to perform
- some other action (type on the keyboard, move the mouse, utilize the
- disks) during the prime generation; this gives the random number
- generator a better chance to gain enough entropy.
- gpg: /Users/oriqu/.gnupg/trustdb.gpg: trustdb created
- gpg: directory '/Users/oriqu/.gnupg/openpgp-revocs.d' created
- gpg: revocation certificate stored as '/Users/oriqu/.gnupg/openpgp-revocs.d/431CBFCDB13DEF3C8C3A2798XXXXYYYYZZZZAAAA.rev'
- public and secret key created and signed.
-
- pub ed25519 2022-09-16 [SC] [expires: 2032-09-13]
- 431CBFCDB13DEF3C8C3A2798XXXXYYYYZZZZAAAA
- uid orixxxxxx (orixxxxx)
- sub cv25519 2022-09-16 [E] [expires: 2032-09-13]
生成secret.gpg的文件
- gpg --export-secret-keys -o secret.gpg
- //记录文件路径后续要用
- /Users/oriqu/.gnupg/secret.gpg

3.3.1 signing.password
在3.2中,生成key过程中设置的密码,就是signing.password
3.3.2 signing.keyId
在3.2中,生成的文件中,有一个.rev文件,其名字的末尾8位就是signing.keyId

然后我们要把这个key id 【ZZZZAAAA】上传到服务器,告诉服务器我们的keyId
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys ZZZZAAA
↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
+++【注意】这步骤必须做,否则后面会在【nexus repository】无法close,会报签名id无法验证成功的错误❌
+++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++
3.3.3 signing.secretKeyRingFile
在3.2中,最后一个命令生成的secret.gpg,记录的路径,就是signing.secretKeyRingFile
3.3.4 最后结果
这个后面gradle.properties要配置
- # signing info
- signing.keyId=ZZZZAAAA
- signing.password=xxxxxxx
- signing.secretKeyRingFile=/Users/oriqu/.gnupg/secret.gpg
配置如下,注意修改成自己的信息
4.1 配置gradle.properties
- #+++++++++++++++++++++++ 上传到maven ++++++++++++++++++++++++
- #其中用到的信息,就是签名步骤生成、获取,记录的,最后两个是自己的SonaType账号
- # signing info
- # 替换成自己的
- signing.keyId=ZZZZAAAA
- # 替换成自己的
- signing.password=xxxxxxx
- # 替换成自己的
- signing.secretKeyRingFile=/Users/oriqu/.gnupg/secret.gpg
-
- # sonatype account
- # 替换成自己的
- sonaUsername=Orixxxx
- # 替换成自己的
- sonaPassword=xxxxxxxxx
4.2 编写gradle发布脚本
在当前项目根目录编写【maven-publish.gradle】
- publishing {
- publications {
- release(MavenPublication) {
- pom {
- // 库信息
- name = 'ori-kv'// 替换成自己的
- description = 'A tool about android Key-Value'// 替换成自己的
- url = 'https://github.com/Orixxxx/ori-kv'// 替换成自己的
- // 开放许可证书,可以自己换其他的
- licenses {
- license {
- name = 'The Apache License, Version 2.0'
- url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- }
- }
- // 开发者信息
- developers {
- developer {
- id = 'orixxxx'// 替换成自己的
- name = 'Orixxxx'// 替换成自己的
- email = 'orixxxx@163.com'// 替换成自己的
- }
- }
- // scm
- scm {
- connection = 'https://github.com/Orixxxx/ori-kv.git'// 替换成自己的
- developerConnection = 'https://github.com/Orixxxx/ori-kv.git'// 替换成自己的
- url = 'https://github.com/Orixxxx/ori-kv'// 替换成自己的
- }
- }
- // aar包依赖信息
- groupId "io.github.orixxx"// 替换成自己的
- artifactId "ori-kv"// 替换成自己的
- version "0.0.1-alpha01"// 替换成自己的
-
- afterEvaluate {
- from components.release
- }
- }
- }
- repositories {
- maven {
- url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
- credentials {
- username sonaUsername // sonatype username
- password sonaPassword // sonatype password
- }
- }
- }
- }
-
- signing {
- sign publishing.publications.release
- }
4.3 目标lib模块的build.gradle
在lib模块的build.gradle 中引用4.2的发布脚本
- plugins {
- ....
- // 添加maven-publish and signing gradle plugin
- id 'maven-publish'
- id 'signing'
- }
- // 应用本地发布到maven的gradle脚本
- apply from: '../maven-publish.gradle'
4.4 sync
最后sync 同步一下,task 就有发布aar 到maven的入口,也可命令行直接执行.
如果在gralde里没有Task 列表,自行百度,设置一下Android Studio ,有个开关勾选,就会出现task列表

5.1 执行发布脚本
如4.4.执行publish后,可以在如下链接,看到发布的lib_xxx.aar

5.2 close包并release
选择对应lib 包,点击Close ,执行成功后,点击release就会发布。通常会有30分钟延迟


然后可在如下链接,按自己一开始设置的groupid,找到对应的aar 包
Index of /repositories/releases
Btw:
想在https://mvnrepository.com/搜索到,需要要等上一段时间,时间有长有短。
5.3 引用这个库
1.在新的项目中,引用.
implementation 'io.github.orixent:ori-kv:0.0.1-alpha1'
2.点击sync ,即可在左侧项目结构 External Libraries找到对应的导包

至此,一个Android库发布到maven central的流程完整走完了。后续仅需要配置新lib 名,版本信息即可发布到maven central。