将项目发布到Maven中央仓库
前言
本文基于官方文档 https://central.sonatype.org/publish/publish-guide/ 编写。
准备阶段
创建账号
已有 Google 或者 Github 账号可以跳过此步骤,可以直接使用它们关联登录。
创建账号步骤如下:
打开官网 https://central.sonatype.com/ 点击右上角的
Sign In,然后在打开的登录页中点击Sign up。注意:邮箱要填写真实的邮箱,有验证的。
创建命名空间
点击右上角的账号,在下拉菜单中选择View Namespaces。
在打开的页面中点击Add Namespace。
在弹出来的对话框中输入自定义的 Namespace。
创建成功之后显示 Namespace 是待验证状态,点击Verify Namespace进行验证。
创建用户 Token
xml
<server>
<id>${server}</id>
<username>drpPHH</username>
<password>XaVS4lZZUGmREOqsEJBYkgNld6tvcXkml</password>
</server>配置 GPG
bash
gpg --version
密码:istr.cn
gpg --gen-key
gpg (GnuPG) 2.4.7; Copyright (C) 2024 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
gpg: directory '/Users/jade/.gnupg' created
Note: Use "gpg --full-generate-key" for a full featured key generation dialog.
GnuPG needs to construct a user ID to identify your key.
Real name: Jade
Email address: liuyulu2@vip.qq.com
You selected this USER-ID:
"Jade <liuyulu2@vip.qq.com>"
Change (N)ame, (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/jade/.gnupg/trustdb.gpg: trustdb created
gpg: directory '/Users/jade/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/Users/jade/.gnupg/openpgp-revocs.d/8CCCA2E2AD29D80B8A90141A14D173E8491F10EA.rev'
public and secret key created and signed.
pub ed25519 2025-07-29 [SC] [expires: 2028-07-28]
8CCCA2E2AD29D80B8A90141A14D173E8491F10EA
uid Jade <liuyulu2@vip.qq.com>
sub cv25519 2025-07-29 [E] [expires: 2028-07-28]
$ gpg --keyserver keyserver.ubuntu.com --send-keys 8CCCA2E2AD29D80B8A90141A14D173E8491F10EA
$ gpg --keyserver keys.openpgp.org --send-keys 8CCCA2E2AD29D80B8A90141A14D173E8491F10EA
$ gpg --keyserver pgp.mit.edu --send-keys 8CCCA2E2AD29D80B8A90141A14D173E8491F10EA
$ gpg --keyserver keys.openpgp.org --recv-keys 8CCCA2E2AD29D80B8A90141A14D173E8491F10EA