创建工单
去https://issues.sonatype.org/secure/Dashboard.jspa新建一个账号,登录后选择Create Issue,选择Community Support - Open Source Project Repository Hosting (OSSRH)以及New Project,其他按照你自己的项目情况填写。 发布完后几小时内会有工作人员问你是否有Group Id对应的那个域名的所有权,如果有的话就回复有(我一开始以为这是系统自动回复,没有管它,结果好几天过后还是没再回复过我…),然后就会得到Configuration has been prepared的回复,这个时候就可以准备发布了。如果自己没有域名的话可以挂在开源的域名下面,例如com.github.flyzy2005,这样一样可以发布。
生成密钥
我用的是windows,直接去https://www.gpg4win.org/download.html下载Gpg4win,安装好后通过gpg --version,出现版本等信息就安装成功了。(如果是Linux,可以通过yum install gpg安装) 设置名字+邮箱,其他可以使用默认值,记住输入的passphrase,后面部署会用到,这里用参考文章里的配图:
$ gpg --gen-
key
gpg (GnuPG)
1.4.19; Copyright (C)
2015 Free Software Foundation, Inc.
This
is free software: you are free
to change
and redistribute it.
There
is NO WARRANTY,
to the extent permitted
by law.
Please
select what kind
of key you want:
(
1) RSA
and RSA (
default)
(
2) DSA
and Elgamal
(
3) DSA (sign only)
(
4) RSA (sign only)
Your selection?
RSA keys may be between
1024 and 4096 bits
long.
What keysize
do you want? (
2048)
Requested keysize
is 2048 bits
Please specify how
long the
key should be valid.
0 =
key does
not expire
<n> =
key expires
in n days
<n>w =
key expires
in n weeks
<n>m =
key expires
in n months
<n>y =
key expires
in n years
Key is valid
for? (
0)
Key does
not expire at all
Is this correct? (y/N) Y
You need a user ID
to identify your
key; the software constructs the user ID
from the Real Name, Comment
and Email Address
in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
Real name: iteblog
Email address: wyphao
.2007@
163.com
Comment: flink-elasticsearch-connector
You selected this USER-ID:
"iteblog (flink-elasticsearch-connector) <wyphao.2007@163.com>"
Change (N)ame, (C)omment, (E)mail
or (O)kay/(Q)uit? O
You need a Passphrase
to protect your secret
key.
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: /c/Users/iteblog/.gnupg/trustdb.gpg: trustdb created
gpg:
key B15C5AA3 marked
as ultimately trusted
public and secret
key created
and signed.
gpg: checking the trustdb
gpg:
3 marginal(s) needed,
1 complete(s) needed, PGP trust model
gpg: depth:
0 valid:
1 signed:
0 trust:
0-,
0q,
0n,
0m,
0f,
1u
pub
2048R/B15C5AA3
2016-
09-
19
Key fingerprint = DB61
9873 924C
020E
20E7 E461
0170 C912 B15C
5AA3
uid iteblog (flink-elasticsearch-connector) <wyphao
.2007@
163.com>
sub 2048R/
31A906E1
2016-
09-
19
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
配置pom.xml
配置项目pom.xml 主要需要配置parent结点,以及增加license、scm、developers信息,这里讲我自己的pom.xml作为一个参考:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0
</modelVersion>
<groupId>cn.flyzy2005
</groupId>
<artifactId>daoutil
</artifactId>
<packaging>jar
</packaging>
<name>daoutil
</name>
<url>http://www.flyzy2005.cn
</url>
<description>A daoUtil based on JdbcTemplate.
</description>
<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>
<url>https://github.com/Flyzy2005/daoutil
</url>
<connection>git@github.com:Flyzy2005/daoutil.git
</connection>
<developerConnection>http://www.flyzy2005.cn
</developerConnection>
</scm>
<developers>
<developer>
<name>fly
</name>
<email>flywf@whu.edu.cn
</email>
<url>http://www.flyzy2005.cn
</url>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8
</project.build.sourceEncoding>
<springversion>4.3.3.RELEASE
</springversion>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework
</groupId>
<artifactId>spring-jdbc
</artifactId>
<version>${springversion}
</version>
</dependency>
<dependency>
<groupId>com.alibaba
</groupId>
<artifactId>fastjson
</artifactId>
<version>1.2.31
</version>
</dependency>
</dependencies>
</project>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
配置Maven的settings.xml 安装配置好maven后,在maven的安装目录下的conf文件夹下找到settings.xml,设置如下:
<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>
123456789101112
账号密码就是第一步申请的Sonatype网站的账号密码。
部署Jar包
通过cmd进入到项目pom.xml所在的目录下,运行如下命令:
mvn clean deploy
-P sonatype
-oss-release -Darguments="gpg.passphrase=设置gpg设置密钥时候输入的Passphrase"
1
如果没有ERROR的话就deploy完成了,如果有ERROR就看错误信息是什么,解决了重新运行命令即可,运行完成的所有文件存在项目目录下的target文件夹里。
上传密钥
两句命令即可,首先查看自己key的编号:
gpg
--list-keys
1
找到 pub对应的那个编号,例如pub 2048R/8C473F5C 上传到key验证库:
-- .. ---
1
release jar包
如果前几个步骤全部正确完成,登录https://oss.sonatype.org/#stagingRepositories后,将Staging Rpositories拉到最下即可看到你刚刚发布的jar包,选择上方的Close,第一次好像会有工作人员回复你第一步Create的那个Issue(我的是回复了)Everything looks good! Now, all that’s left for you is to select that staging repository and click the “Release” button.,然后再点击Release即可,等2个小时左右即可在http://search.maven.org/看到你发布的jar包。
更新Jar包
只需要更新pom.xml里的version,再重新depoly,重新close,再release即可。(如果version没有改变则会覆盖掉中央仓库的当前版本)。
参考
主要参考文章:https://www.iteblog.com/archives/1807.html,讲解的很清楚。 最后附上自己的项目以及Issue作为参考: https://issues.sonatype.org/browse/OSSRH-30758 https://github.com/Flyzy2005/daoutil