发布依赖到Maven中央仓库

创建Sonatype账号

Sign up for Jira https://issues.sonatype.org/secure/Signup!default.jspa

提交发布申请

提交发布申请

  • Project:选择【Community Support - Open Source Project Repository Hosting (OSSRH)】

  • Issue Type:选择【New Project】

  • Summary:简单描述一下项目的作用

  • Group Id:如果有自己的域名就填域名(倒序填写:com.xxxxx),否则填io.github.GitHub用户名

  • Project URL:项目地址

  • SCM url: git clone地址

最后点Create按钮即可,等待Snortype给你发邮件,会发到你注册账号的邮箱里。

收到邮件后,可以登陆Sonatype查看你之前提交Issue。评论中会提示你验证域名的归属,如果是自己的域名,则去域名服务商那里的配置页面上加一条TXT解析记录,内容为类似这样的一串字符:OSSRH-80732。然后打开命令窗口,输入nslookup -type=TXT 域名,最终结果包含OSSRH-80732,则表示配置成功。

然后将Issue的状态修改为Open,这个按钮在Issue的标题下方。

修改状态为Open

修改完状态之后,就只需要等待了。如果没什么问题,Sonatype会审批通过。一样的,也会给你发邮件通知。

创建gpg密钥

使用 PGP 签名 - 中央存储库文档 (sonatype.org)

# 生成密钥,根据提示输入“用户名”、“邮箱”、“密码”,最后输入大写字母O
gpg --gen-key

# 查看密钥
gpg --list-key

/c/Users/XXX/.gnupg/pubring.kbx
---------------------------------
pub rsa3072 2023-06-05 [SC] [expires: 2025-06-04]
这个位置会显示公钥字符串
uid [ultimate] 用户名 <邮箱>
sub rsa3072 2023-06-05 [E] [expires: 2025-06-04]

# 发布密钥(必要),用于后续发布maven时,sonatype需要验证
gpg --keyserver keyserver.ubuntu.com --send-keys 公钥字符串

配置settings.xml

<!-- servers 中增加一个server -->
<server>
<id>ossrh</id>
<username>sonatype登陆账号,不是邮箱</username>
<password>sonatype登陆密码</password>
</server>

<!-- profiles 中增加一个profile -->
<profile>
<id>gpg</id>
<activation>
<file>
<exists>${user.home}/.gnupg</exists>
</file>
</activation>
<properties>
<gpg.executable>gpg路径,需要配置到系统环境变量中</gpg.executable>
<gpg.passphrase>创建key时设置的密码</gpg.passphrase>
</properties>
</profile>

<!-- activeProfiles 中增加activeProfile -->
<activeProfile>gpg</activeProfile>

配置pom.xml

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LISCENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<connection>scm:git克隆地址</connection>
<developerConnection>scm:git克隆地址</developerConnection>
<url>GitHub项目地址</url>
</scm>

<developers>
<developer>
<name>名字</name>
<email>邮箱</email>
<timezone>+8</timezone>
</developer>
</developers>

<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>
</distributionManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>8</source>
<target>8</target>
<fork>true</fork>
<verbose>true</verbose>
<encoding>UTF-8</encoding>
<compilerArguments>
<sourcepath>
${project.basedir}/src/main/java
</sourcepath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<additionalOptions>
<additionalJOption>-Xdoclint:none</additionalJOption>
</additionalOptions>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>