Sonatype站点账号和工单申请

1,到sonatype jira站点:直达链接,注册账号,创建jira工单,填写如下:

1
2
3
4
5
6
项目:Community Support - Open Source Project Repository Hosting
类型:new project
概要:项目的描述
Group Id:项目的groupid,最好是自己的域名
Project Url:项目地址
SCM Url:项目Git地址

然提交成功后,注意关注jira工单或者邮箱,因为工作人员会验证你填写的信息,主要是group id域名的所有权。

2,验证域名所有权,需要到域名新增一个与jira工单关联的Txt类型的解析记录,配置示例:

1
2
3
类型:txt
主机记录:OSSRH-56616
记录值:https://issues.sonatype.org/browse/OSSRH-56616

配置完成后,到jira工单下留言告知,留言示例:

1
This domain name is mine,And NDS TXT record has configured

3,域名验证通过后,会邮件通知你结果,并告知下一步操作,通知示例:

1
2
3
4
5
cn.soilove has been prepared, now user(s) guolin can:
* Deploy snapshot artifacts into repository https://oss.sonatype.org/content/repositories/snapshots
* Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2
* Release staged artifacts into repository 'Releases'
please comment on this ticket when you promoted your first release, thanks

如果这个时候,你已经准备好deploy,那么就修改jira单的 Already Synced to Central为yes,表明你已经准备好同步到中央仓库

1
Already Synced to Central = yes 

4,最后,等你将项目打包好,推送到仓库后,再次到jira工单留言告知,开启同步。你也可以贴上打包发布成功的日志,留言示例:

1
I have successfully closed and released.

正常情况下,工作人员会回复如下内容:

1
2
3
Central sync is activated for cn.soilove. 
After you successfully release, your component will be published to Central, typically within 10 minutes,
though updates to search.maven.org can take up to two hours.

工程pom和maven配置

1,修改maven settings.xml文件,新增server配置

1
2
3
4
5
<server>
<id>ossrh</id>
<username>账号</username>
<password>密码</password>
</server>

2,修改工程pom.xml文件,增加如下配置,根据实际工程情况修改:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<!-- 发布者信息 -->
<developers>
<developer>
<name>guolin</name>
<email>root@soilove.cn</email>
<url>https://blog.soilove.cn</url>
</developer>
</developers>
<!--scm信息-->
<scm>
<url>https://github.com/Ln-guolin/spring-boot-starter-oss</url>
</scm>
<!--licenses信息 -->
<licenses>
<license>
<name>GNU General Public License v3.0</name>
<url>http://www.gnu.org/licenses/agpl-3.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<!--打包配置 -->
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</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.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration> <!-- add this to disable checking -->
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!--仓库配置 -->
<distributionManagement>
<repository>
<id>ossrh</id>
<name>Maven Central Staging Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

推送jar到中央仓库

1,安装gpg,我这里是基于mac系统的,所以直接用brew安装了

1
brew install gpg

2,生成密钥对,会提示输入姓名、邮箱等字段,其它直接回车,直到输入密码界面,密码一定要输入记牢,后面打包会进行验证

1
gpg --gen-key

命令执行完成后,会输出公钥和私钥信息,一定要记录下来。万一忘记了可以“gpg --list-keys”提供公钥部分信息查询,输出如下:

1
2
3
4
5
6
7
8
9
gpg: /Users/chenguolin/.gnupg/trustdb.gpg:建立了信任度数据库
gpg: 密钥 C49487317C8BXXXX 被标记为绝对信任
gpg: 目录‘/Users/chenguolin/.gnupg/openpgp-revocs.d’已创建
gpg: 吊销证书已被存储为‘/Users/chenguolin/.gnupg/openpgp-revocs.d/E8C38745076F91ADEF800BADC49487317C8BXXXX.rev’
公钥和私钥已经生成并被签名。
pub rsa2048 2020-04-14 [SC] [有效至:2022-04-14]
E8C38745076F91ADEF800BADC49487317C8BXXXX
uid chenguolin <root@soilove.cn>
sub rsa2048 2020-04-14 [E] [有效至:2022-04-14]

3,推送公钥(pub)到远程服务,并验证是否推送完成

1
2
gpg --keyserver hkp://keyserver.ubuntu.com:80 --send-keys 公钥
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 公钥

4,执行打包发布,注意!一定要在系统的命令窗口执行,idea的terminal中执行会报错,无法呼出密码输入窗口

1
2
export GPG_TTY=$(tty)
mvn clean deploy

打包成功,提示“BUILD SUCCESS”后,就完成了。

其他

我的工程和工单信息:
工单:OSSRH-56616
txt解析:ossrh-56616.soilove.cn
工程地址:spring-boot-starter-oss

相关站点,账号通用:
nexus仓库: oss.sonatype.org
资源查询地址: search.maven.org