一、步驟
1.注冊
https://issues.sonatype.org/secure/Signup!default.jspa
2.登錄
https://issues.sonatype.org/login.jsp
3.創(chuàng)建issue
https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134創(chuàng)建好的就是如下這種

創(chuàng)建完之后會收到一封郵件,然后我們創(chuàng)建好的issue就如下,后面跟官方的一些交互和問答基本上都是在這里完成https://issues.sonatype.org/browse/OSSRH-49415
4.創(chuàng)建完畢后等待通知
我這里遇到這樣的一個問題,后來收到的官方的回復(fù)如下
Please create a public repo called https://github.com/simonalong/OSSRH-49415 to verify github account ownership.
If you do not own this github account, please read:
http://central.sonatype.org/pages/choosing-your-coordinates.html
好像是我還得創(chuàng)建一個公共的倉庫,名字叫OSSRH-49415,去自己的賬號中創(chuàng)建一個這樣的公共倉庫就好了,創(chuàng)建完之后在issue中回復(fù)下就好,比如

最后會收到對應(yīng)的回復(fù),比如

整個評論回復(fù)如下

5.生成公鑰
mac 進(jìn)行安裝gpg
brew install -v gpg
生成密鑰
gps --gen-key

輸入o,就是表示確認(rèn),然后兩次密碼確認(rèn)

查看公鑰
gpg --list-key

6.發(fā)布公鑰
主要是將我們的公鑰發(fā)布給官方,讓其能夠解析我們本地用私鑰加密后的數(shù)據(jù)
gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 你的公鑰
比如
gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 14A4854E9312A84AF051C61494254BDBB854A311
查看是否上傳成功
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 你的公鑰

7.配置maven
我這里新建一個settings.xml,然后在里面添加對應(yīng)的賬戶信息
<servers>
<server>
<id>oss</id>
<username>用戶名</username>
<password>密碼</password>
</server>
</servers>
8.代碼中配置代碼發(fā)布器
<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>
9.上傳
這里上傳一定不要點擊idea的deploy按鈕,因為deploy和maven-gpg-plugin結(jié)合的不是很好,那個gpg插件無法運行,一定要用客戶端或者iterm即可。運行這樣運行
mvn clean deploy --settings /Users/zhouzhenyong/.m2/setting_maven_center.xml
其中會提示輸入gpg的密碼,輸入即可
10.查看
https://oss.sonatype.org/#stagingRepositories我們可以去這里查看,首先登陸,賬號是我們注冊的用戶名和密碼,然后點擊左側(cè)的“Staging Respositories(暫存?zhèn)}庫)”,然后在右上角輸入groupId,就可以搜索我們的這個

如果在這里能夠找到,說明已經(jīng)發(fā)布到這里算是成功了,但是還需要工作人員進(jìn)行審計,需要在我們的Issue中通知一下工作人員即可在下面的評論中,添加這樣的一句評論
The component has been successfully released,please confirm
11.關(guān)閉釋放倉庫
這里其實是暫存庫,我們發(fā)布到這里之后,如果發(fā)布成功,則進(jìn)行關(guān)閉最后就可以了,關(guān)閉的時候,其中確認(rèn)框中輸入該項目的介紹信息,這個是會在界面上展示用于搜索的

關(guān)閉后,查看下面,主要是用于審核,如果成功了,則為下面的。

這里也遇到了一些問題,具體的問題看下面的問題即可,關(guān)閉完成的話,點擊release,也就是將當(dāng)前的這個庫釋放,并自動發(fā)送到中央倉庫

12.回復(fù)issue
當(dāng)我們發(fā)布完成之后,我們可以在issue下面回復(fù)一條說明自己已經(jīng)完成了組件的發(fā)布,請求確認(rèn),比如我的:
Although I have encountered some problems, finaly I have released my staging repo.The component has been successfully released,please confirm, thanks very much
13.查看中央倉庫
當(dāng)那邊的工作人員審批完成之后,就可以將這個issue關(guān)閉了,一般過十分鐘或者兩個小時左右,我們就可以去中央倉庫https://search.maven.org/中查看,應(yīng)該就可以看到我們的這個項目了,對于更加流行的倉庫https://mvnrepository.com,可能需要好幾個星期之后才會看到,主要是同步慢。我這邊是過了一天之后,這邊就可以查看了

14.以后的發(fā)布
以后如果發(fā)布該項目,則直接maven發(fā)布即可,然后close,然后release即可。不用像上面一樣創(chuàng)建issue了,如果發(fā)布的項目跟該項目group相同,則按照maven發(fā)布->close->release即可,如果不同則要開始注冊issue了。不過對于每次發(fā)布都手動close和release有點麻煩的話,可以使用nexus-staging-maven-plugin這個插件,但是建議第一次不要使用該插件,手動執(zhí)行是可以填寫一些描述的,但是這個插件執(zhí)行是不會有任何再輸入的,而是一次性就執(zhí)行完,最后等十幾分鐘就直接發(fā)到倉庫中心了。
附錄:
1.完整的pom參考
pom.xml 中必須包括:name、description、url、licenses、developers、scm 等基本信息,使用了 Maven 的 profile 功能,只有在 release 的時候才創(chuàng)建源碼包、文檔包、使用 GPG 進(jìn)行數(shù)字簽名。
<?xml version="1.0" encoding="UTF-8"?>
<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.github.simonalong</groupId>
<artifactId>mikilin</artifactId>
<packaging>jar</packaging>
<version>1.4.0</version>
<name>Mikilin</name>
<url>https://github.com/SimonAlong/Mikilin</url>
<description>對象屬性核查工具</description>
<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>zhouzhenyong</name>
<email>simonalongs@126.com</email>
<roles>
<role>developer</role>
</roles>
</developer>
</developers>
<scm>
<connection>scm:git:git@github.com:SimonAlong/Mikilin.git</connection>
<developerConnection>scm:git:git@github.com:SimonAlong/Mikilin.git</developerConnection>
<url>git@github.com:SimonAlong/Mikilin.git</url>
</scm>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<!--spock測試框架-->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.2-groovy-2.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>groovy-all</artifactId>
<groupId>org.codehaus.groovy</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.8</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
</configuration>
<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.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<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>
</project>
pom.xml 中必須包括:name、description、url、licenses、developers、scm 等基本信息,使用了 Maven 的 profile 功能,只有在 release 的時候才創(chuàng)建源碼包、文檔包、使用 GPG 進(jìn)行數(shù)字簽名。
參考:
http://www.itdecent.cn/p/8c3d7fb09bce
http://www.itdecent.cn/p/8c3d7fb09bce
http://www.itdecent.cn/p/d0e43416aaf6
http://www.itdecent.cn/p/d0e43416aaf6
https://www.iteblog.com/archives/1807.html
https://www.iteblog.com/archives/1807.html
https://zhuanlan.zhihu.com/p/41650855
https://zhuanlan.zhihu.com/p/41650855
https://my.oschina.net/u/2335754/blog/476676
https://my.oschina.net/u/2335754/blog/476676
問題:
1.公鑰上傳不上去
如果遇到上傳公鑰上傳不上去的問題,可以查看這里
2.maven-gpg-plugin問題
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.6:sign (sign-artifacts) on project mikilin: Exit code: 2 -> [Help 1]
最終的原因是不能用idea 自帶的那個終端,<br />注意:!?。。。。。。。。。。?!不要使用idea自帶的終端,真想說一百字的臟話,嘗試了好久,各種問題都嘗試了,還有就是要在.bashrc中添加如下的一個即可
export GPG_TTY=$(tty)
3.xxx.asc文件找不到
這個asc文件其實是gpg文件生成的,也就是上面maven-gpg-plugin文件是必須要生效才能生成這些文件的<br />[圖片上傳失敗...(image-25c101-1561878176712)]<br />
4.版本上傳注意點
第一次不能上傳SNAPSHOT版本