已申请: https://issues.sonatype.org/browse/OSSRH-66501
操作步骤:
1. 注册JIRA账号
JIRA是一个项目管理服务,类似于国内的Teambition。Sonatype通过JIRA来管理OSSRH仓库。
注册地址:https://issues.sonatype.org/secure/Signup!default.jspa
需要填写 Email 、 Full Name 、 Username 以及 password,其中
Username 与 Password 后面的步骤需要用到,请记下来。
2. 创建issue
通过在JIRA上创建issue来申请发布新的jar包,Sonatype的工作人员会进行审核,审核不算严格,一般按照要求填写不会有问题。
创建链接:https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134
创建issue的时候需要填写下面这些信息:
Summary
Description
Group Id
Project URL
SCM url
可以参考这个发布内容:OSSRH-45238
由于时差,前一天创建issue,第二天早上才会有回应。当issue的status变为 RESOLVED** **,我们就可以进行下一步操作了。
3. 安装并配置GPG
发布到Maven仓库中的所有文件都要使用GPG签名,以保障完整性。因此,我们需要在本地安装并配置GPG。
安装GPG
MacBook安装GPG非常简单,下载并安装GPG Suite即可。
Mac的命令是 gpg2
,Windows/Linux 为 gpg
生成GPG密钥对
gpg2 --gen-key
生成密钥时将需要输入name、email以及password。password在之后的步骤需要用到,请记下来。
Mac 建议使用图形化界面操作,不易出错
上传GPG公钥
将公钥上传到公共的密钥服务器,这样其他人才可以通过公钥来验证jar包的完整性。
# 上传,如果不成功,可以多尝试几次
gpg2 --keyserver hkp://pool.sks-keyservers.net --send-keys CAB4165C69B699D989D2A62BD74A11D3F9F41243
# 查看
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys CAB4165C69B699D989D2A62BD74A11D3F9F41243
其中 **CAB4165C69B699D989D2A62BD74A11D3F9F41243**
为密钥的ID,可以通过 **gpg2 –list-keys**
命令查看。
4. 配置 Maven 的 setting.xml
setting.xml
为Maven的全局配置文件,在MacBook上的位置为 /usr/local/Cellar/maven/3.5.4/libexec/conf/settings.xml,我们需要将 第1步 配置的Username和Password添加到 <servers></servers>
标签中,这样我们才能将 jar 包部署到 Sonatype OSSRH 仓库:
<servers>
<server>
<id>eoysky</id>
<username>jonnyhub</username>
<password>123456</password>
</server>
</servers>
5. 配置项目的 pom.xml
pom.xml挺长的。根据 Sonatype OSSRH 的要求,以下信息都必须配置:
- Supply Javadoc and Sources
- Sign Files with GPG/PGP
- Sufficient Metadata
- Correct Coordinates
- Project Name, Description and URL
- License Information
- Developer Information
- SCM Information
配置时参考我的 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>com.fundebug</groupId>
<artifactId>fundebug-java-notifier</artifactId>
<version>0.2.0</version>
<packaging>pom</packaging>
<name>fundebug-java-notifier</name>
<url>https://github.com/Fundebug/fundebug-java-notifier</url>
<description>Capture Java and Spring exceptions automatically</description>
<licenses>
<license>
<name>Server Side Public License</name>
<url>https://www.mongodb.com/licensing/server-side-public-license</url>
<distribution>repo</distribution>
<comments>A not business-friendly OSS license</comments>
</license>
</licenses>
<scm>
<url>https://github.com/Fundebug/fundebug-java-notifier</url>
<connection>https://github.com/Fundebug/fundebug-java-notifier.git</connection>
</scm>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<developers>
<developer>
<name>kiwenlau</name>
<id>kiwenlau</id>
<email>kiwenlau@gmail.com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<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>
<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
<modules>
<module>fundebug-java</module>
<module>fundebug-spring</module>
<module>examples/hello-world</module>
<module>examples/spring-rest-api</module>
</modules>
</project>
6. 发布jar包
执行mvn clean deploy处理,即可将jar包发布到Sonatype OSSRH仓库。
mvn clean deploy -projects fundebug-java,fundebug-spring
我们的项目fundebug-java-notifier含有多个模块,仅需部署fundebug-java与fundebug-spring,因此使用-projects选项来指定。
第一次执行mvn clean deploy命令时,需要输入GPG密钥的密码。
mvn clean deploy命令执行成功的输出是这样的(部分日志):
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] fundebug-java 0.2.0 ................................ SUCCESS [ 22.183 s]
[INFO] fundebug-spring 0.2.0 .............................. SUCCESS [ 16.383 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 38.728 s
[INFO] Finished at: 2019-01-12T20:10:16+08:00
[INFO] ------------------------------------------------------------------------
7. close 并 release
**mvn clean deploy**
命令执行成功,使用 JIRA 账号登陆:
https://oss.sonatype.org/#stagingRepositories 就可以看到你所发布的jar包了。
选中对于的 repository 之后,点击箭头所指的 close,close 时会检查发布的构件是否符合要求。
若符合要求,则 close 成功,成功之后点击箭头所指的 release,即可正式将 jar 包发布到 Sonatype OSSRH 仓库。
release成功大概2个小时之后,该构件就会同步到 Maven中央仓库:
附录:
pom.xml 示例:
<?xml version="1.0" encoding="utf-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>~/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<proxies/>
<servers>
<!-- <server>
<id>ossrh</id>
<username>6d2RqC5U</username>
<password>UvG1ysoETQ8u1wnkdT74G1tEDKDTx2k8Qmmzc1VnOjfD</password>
</server> -->
<server>
<id>ossrh</id>
<username>jonnyhub</username>
<password>Rain@8240...</password>
</server>
<!-- <server>
<id>ossrh</id>
<username>jonnyhub</username>
<password>Rain@8240...</password>
</server> -->
<!-- <server>
<id>sonatype-nexus-snapshots</id>
<username>jonnyhub</username>
<password>Rain@8240...</password>
</server>-->
</servers>
<mirrors>
<mirror>
<id>huaweicloud-cdn</id>
<mirrorOf>*</mirrorOf>
<url>https://repo.huaweicloud.com/repository/maven/</url>
</mirror>
<mirror>
<id>huaweicloud</id>
<mirrorOf>*</mirrorOf>
<url>https://mirrors.huaweicloud.com/repository/maven/</url>
</mirror>
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>central repo</name>
<url>https://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
<!-- profiles -->
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg2</gpg.executable>
<gpg.passphrase>rain8240</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
setting.xml 示例:
<?xml version="1.0" encoding="utf-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>~/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<proxies/>
<servers>
<server>
<id>ossrh</id>
<username>jonnyhub</username>
<password>you_central_password</password>
</server>
<!-- <server>
<id>ossrh</id>
<username>jonnyhub</username>
<password>you_central_password</password>
</server> -->
<!-- <server>
<id>sonatype-nexus-snapshots</id>
<username>jonnyhub</username>
<password>you_central_password</password>
</server>-->
</servers>
<mirrors>
<mirror>
<id>huaweicloud-cdn</id>
<mirrorOf>*</mirrorOf>
<url>https://repo.huaweicloud.com/repository/maven/</url>
</mirror>
<mirror>
<id>huaweicloud</id>
<mirrorOf>*</mirrorOf>
<url>https://mirrors.huaweicloud.com/repository/maven/</url>
</mirror>
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>central repo</name>
<url>https://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>阿里云公共仓库</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>
<!-- profiles -->
<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg2</gpg.executable>
<gpg.passphrase>YourGPGPassword</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>