发布jar包到Maven中央库--小记

最近项目选用了vert.x,故此简单的封装了一下,好达到从spring体系到vert.x平滑过度,减少其他人的学习成本,而后发布到Maven中央库,记录一下~

create issues

首先需要在sonatype中创建issues,没有帐号的需要注册一下(帐号密码后续会有用到)。

类似如图:issues

这里有个注意的点,这个group Id需要自己有个域名或者使用github的,类似io.github.7le or com.github.7le。这里我自己买了个域名,价格动人。当issue的Status变为RESOLVED,就代表已经通过了,如果有什么问题,会有留言告诉你如何修改。

gpg & maven

Windows的话可以到gpg下载gpg4win。Linux可以通过yum install gpg命令安装gpg。

我们可以通过gpg --version,来查看安装的gpg
gpg-version

执行gpg --gen-key 按照如下的命令设置好你的名字,邮箱。不过输入Passphrase的值需要记住,这个相当于密钥的密码

然后设置maven的配置,在setting.xml
需要设置

1
2
3
4
5
6
7
8
9
10
11
12
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>Sonatype网站的账号</username>
<password>Sonatype网站的密码</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>Sonatype网站的账号</username>
<password>Sonatype网站的密码</password>
</server>
</servers>

以及

1
2
3
4
5
6
7
8
9
10
11
12
13
<profile>
<id>shine</id>
<distributionManagement>
<snapshotRepository>
<id>oss</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>oss</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>

在自己的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
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>

....

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<tag>master</tag>
<url>https://github.com/7le/vertx-shine</url>
<connection>scm:git:https://github.com/7le/vertx-shine.git</connection>
<developerConnection>scm:git:https://github.com/7le/vertx-shine.git</developerConnection>
</scm>
<developers>
<developer>
<name>7le</name>
<email>silk.heqian@gmail.com</email>
<organization>ArkStack</organization>
<organizationUrl>7le.top</organizationUrl>
</developer>
</developers>

deploy & release

一切就绪后,在命令行输入
mvn clean deploy -P sonatype-oss-release -Darguments="gpg.passphrase=设置的Passphrase"
operation

成功之后可以到Neuxs查看发布好的jar包:
manager

按着步骤,先close 再release。manager2

这里在close的会报一个错误,错误如下

1
2
3
4
5
6
typeId	signature-staging
failureMessage No public key: Key with id: (your_id) was not able to be located on http://pgp.mit.edu:11371/. Upload your public key and try the operation again.
failureMessage No public key: Key with id: (your_id) was not able to be located on http://keyserver.ubuntu.com:11371/. Upload your public key and try the operation again.
failureMessage No public key: Key with id: (your_id) was not able to be located on http://pool.sks-keyservers.net:11371/. Upload your public key and try the operation again.
failureMessage No public key: Key with id: (your_id) was not able to be located on http://pgp.mit.edu:11371/. Upload your public key and try the operation again.
.....

这里将your_id,上传到第三方的key验证库,如下
gpg-addKey

然后再等一段时间,就可以在Maven中央仓库搜到了。正式版本和SNAPSHOT大家可以自己选择~

search

如果你也需要,可以戳vertx-shine-web
完。^.^

更多精彩 戳我