注册地址:https://issues.sonatype.org/secure/Signup!default.jspajava
使用了JIRA来管理流程,记住用户名和密码,后面会用到。git
登陆进入后,create Issuegithub
以后回收到评论:apache
若是是你的域名你就能够回复,xxx.com is my domain 完了等待审核,通常一天时间;api
审核经过后工做人员会回复以下:xcode
下载gpg4win:http://files.gpg4win.org/服务器
选(带vanilla的) gpg4win-vanilla-2.3.4.exe网络
gpg --version
gpg --gen-key
会让你选择加密的方式:dom
lease select what kind (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only)
选1,以后往下,会让你输入用户名和邮箱,还有一个Passphase,至关于密钥库密码,不要忘记jsp
gpg --list-keys
pub 2048R/99F1B186 2018-02-02 uid [ultimate] YaleRen (hello) <royal8848@163.com> sub 2048R/DBD61A9E 2018-02-02
99F1B186
就是公钥ID
gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 99F1B186
此后,可以使用本地的私钥来对上传构件进行数字签名,而下载该构件的用户可经过上传的公钥来验证签名,也就是说,你们能够验证这个构件是否由本人上传的,由于有可能该构件被坏人给篡改了
#: gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 99F1B186 gpg: requesting key 99F1B186 from hkp server pool.sks-keyservers.net gpg: key 99F1B186: "YaleRen (hello) <royal8848@163.com>" not changed gpg: Total number processed: 1 gpg: unchanged: 1
找到maven的全局配置文件settings.xml,在里面找到 节点,这个节点默认是注释掉的,增长以下配置:
<servers> <server> <id>oss</id> <username>Sonatype 用户名</username> <password>Sonatype 密码</password> </server> </servers>
<project> ... <name>dexcoder-assistant</name> <description>dexcoder-assistant is a rapid development kit.</description> <url>http://www.dexcoder.com/</url> <licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> </license> </licenses> <developers> <developer> <name>selfly</name> <email>selfly@foxmail.com</email> </developer> </developers> <scm> <connection>scm:git:git@github.com:selfly/dexcoder-assistant.git</connection> <developerConnection>scm:git:git@github.com:selfly/dexcoder-assistant.git</developerConnection> <url>git@github.com:selfly/dexcoder-assistant.git</url> </scm> ... <profiles> <profile> <id>release</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> <skip>true</skip> </configuration> </plugin> <!-- Source --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!-- Javadoc --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.9.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!-- GPG --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <version>1.5</version> <executions> <execution> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <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> </profiles> ... </project>
pom.xml中必须包括:name、description、url、licenses、developers、scm 等基本信息,使用了 Maven 的 profile 功能,只有在 release 的时候,建立源码包、文档包、使用 GPG 进行数字签名。
此外,snapshotRepository 与 repository 中的 id 必定要与 setting.xml 中 server 的 id 保持一致。
若是是多模块项目的话,只须要在父pom.xml中声明这些,子pom.xml中只须要修改相应的一些信息,如name标签。
mvn clean deploy -Dmaven.test.skip=true -P release
当执行以上 Maven 命令时,会自动弹出一个对话框,须要输入上面提到的 Passphase,它就是刚才设置的 GPG 密钥库的密码。
随后会看到大量的 upload 信息,由于在国内网络的缘故,时间有点久,耐心等待吧。
注意:此时上传的构件并未正式发布到中央仓库中,只是部署到 OSS 中了,下面才是真正的发布。
在 OSS 中,使用本身的 Sonatype 帐号登陆后,可在 Staging Repositories 中查看刚才已上传的构件,这些构件目前是放在 Staging 仓库中,可进行模糊查询,快速定位到本身的构件(要拉到最下面
)。
此时,该构件的状态为 Open,须要勾选它,而后点击 Close 按钮。系统会自动验证该构件是否知足指定要求,当验证完毕后,状态会变为 Closed
最后,点击 Release 按钮来发布该构件
这里页面可能要刷新一下才能看到新的状态。
这个前面的Sonatype工做人员其实在审核你的Issue时,在comment中已经提示你了,My repository had released!
在Issue下面回复一条“构件已成功发布”的评论,这是为了通知 Sonatype 的工做人员为须要发布的构件作审批,发布后会关闭该Issue。
这个,又只能等待了,固然他们晚上上班,仍是次日看。当审批经过后,将会收到邮件通知。
这时,就能够在maven的中央仓库中搜索到本身发布的构件了,之后能够直接在pom.xml中使用了!
中央仓库搜索网站:http://search.maven.org/
第一次成功发布以后,之后就不用这么麻烦了,能够直接使用Group Id发布任何的构件,固然前提是Group Id没有变。
之后的发布流程:
a)构件完成后直接使用maven在命令行上传构建;
b)在https://oss.sonatype.org/ close并release构件;
c)等待同步好(大约2小时多)以后,就可使用了