所有運維資料都在HDIS-Solution中能找到,歡迎star。
同時也歡迎關注我的微服務Framework:HDIS-Framework,歡迎star。
如何向maven中央倉庫提交jar
1.0JIRA準備
1.1註冊一個JIRA賬號
https://issues.sonatype.org/secure/Signup!default.jspa
1.2創建一個新工程的工單
注意!Project請選擇‘Community Support - Open Source Project Repository Hosting (OSSRH)’
https://issues.sonatype.org/secure/CreateIssue!default.jspa
1.3填寫工單內容
注意!只需要填寫
Group Id:項目Maven的GroupID,注意,GroupID是一個需要你購買了的域名,否則審覈員會DISS你。
Project URL:你的git項目主頁,如:(https://gitee.com/w6513017/HDIS-Framework)
SCM url:可拉取項目的git地址,如:(https://gitee.com/w6513017/HDIS-Framework.git)
1.4等待審覈
進入工單頁面查看Activity ===> Comments部分,此處爲你和審覈員的聊天內容。
1.5審覈完畢
當頁面上審覈狀態(Status)爲resolved時,纔可以向中央倉庫提交jar包。
審覈通過後會出現以下內容:
Permalink
twatson Thad Watson added a comment - Yesterday
Configuration has been prepared, now you can:
Deploy snapshot artifacts into repository https://oss.sonatype.org/content/repositories/snapshots
Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2
Promote staged artifacts into repository ‘Releases’
Download snapshot and release artifacts from group https://oss.sonatype.org/content/groups/public
Download snapshot, release and staged artifacts from staging group https://oss.sonatype.org/content/groups/staging
please comment on this ticket when you promoted your first release, thanks
注意最後一句,當你發佈第一個release後,請通知審覈員一聲。否則他不會爲你激活向中央倉庫同步。到時候你就玩蛇了!
2.0Maven部署準備
2.1完善POM信息
需要在POM中完善name、description、url、license、scm、developer的信息
<name>HDIS-Framework</name>
<description>支撐Java項目的,基於SpringBoot、阿里雲的一系列公共組件,規定的一系列架構約束。</description>
<url>https://gitee.com/w6513017/HDIS-Framework</url>
<licenses>
<license>
<name>Apache License Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>
<scm>
<url>https://gitee.com/w6513017/HDIS-Framework.git</url>
<connection>scm:git:https://gitee.com/w6513017/HDIS-Framework.git</connection>
<developerConnection>scm:git:https://gitee.com/w6513017/HDIS-Framework.git</developerConnection>
<tag>master</tag>
</scm>
<developers>
<developer>
<name>Nicholas.ZW.H</name>
<email>[email protected]</email>
</developer>
</developers>
2.2配置distributionManagement
需要在POM文件中配置distributionManagement
<distributionManagement>
<!--快照版本地址-->
<snapshotRepository>
<id>snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<!--正式版本地址-->
<repository>
<id>releases</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
</distributionManagement>
2.3配置JIRA的賬號和密碼
在/home/.m2/settings.xml中設置JIRA的賬號和密碼
<settings>
<servers>
<server>
<id>snapshots</id>
<username>你的用戶名</username>
<password>你的密碼</password>
</server>
<server>
<id>releases</id>
<username>你的用戶名</username>
<password>你的密碼</password>
</server>
</servers>
</settings>
2.4配置上傳插件
配置源代碼插件、文檔插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
2.5gpg相關配置(坑已踩完,放心使用)
2.5.1安裝gpg程序
2.5.1.1windows
下載gpg。注意!請選擇GnuPG 1.4版本,高版本插件支持有問題!
下載地址:
https://www.gnupg.org/download/index.html
配置環境變量
將gpg的安裝目錄配置進path
2.5.1.2linux
安裝gnupg
yum install -y gnupg
安裝rng-tools,補充熵池。否則它在生成密鑰的時候會卡住!
yum install -y rng-tools
配置rng-tools
echo 'EXTRAOPTIONS="--rng-device /dev/urandom"' >/etc/sysconfig/rngd
service rngd restart
chkconfig rngd on
2.5.2生成gpg密鑰與上傳gpg密鑰
2.5.2.1生成密鑰
按照提示一步步執行即可
gpg --gen-key
2.5.2.2查看密鑰
使用命令查看key
gpg --list-keys
2.5.2.3上傳公鑰
得到密鑰以後需要上傳至公鑰服務器。
maven在發佈release版本時需要在公鑰服務器上拉取密鑰,進行驗證。
以下爲公鑰服務器列表,國內只有它能訪問!公鑰服務器之間會自動同步。
keyserver.ubuntu.com
上傳公鑰
gpg --keyserver hkp://keyserver.ubuntu.com --send-keys [公鑰ID]
驗證公鑰
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys [公鑰ID]
2.5.3密鑰相關操作(可跳過瀏覽)
2.5.3.1導出密鑰
導出公鑰
gpg --armor --output public-key --export [用戶ID]
導出私鑰
gpg --armor --output private-key --export-secret-keys [用戶ID]
2.5.3.2導入密鑰
導入密鑰
gpg --import [密鑰文件]
從公鑰服務器導入公鑰
gpg --keyserver hkp://subkeys.pgp.net --search-keys [用戶ID]
2.5.3.3刪除密鑰
刪除私鑰
gpg --delete-secret-keys [用戶uid]
刪除公鑰
gpg --delete-keys [用戶uid]
2.5.4配置gpg加密插件
由於發佈releases環境纔會用到gpg,因此可以設置profile進行環境的隔離。
注意!插件版本必須使用1.4版本,1.4以上版本會卡住。
注意!properties需要設置gpg.exe地址。
<properties>
<gpg.executable>D:\Program Files (x86)\GNU\GnuPG\gpg.exe</gpg.executable>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
3.0部署
3.1發佈snapshot版本
3.1.1Maven設置snapshot版本
修改version,並加上‘-SNAPSHOT’後綴
-SNAPSHOT
3.1.2發佈
注意:snapshot版本提交時,並不需要gpg簽名,直接提交即可。
執行:
mvn clean deploy
3.1.3驗證
在snapshot倉庫中可以看到已經發布的snapshot版本
snapshot倉庫地址:
https://oss.sonatype.org/content/repositories/snapshots/
3.2提交release版本
3.2.1Maven設置release版本
修改version,並取消‘-SNAPSHOT’後綴
3.2.2發佈
注意:release版本提交時,需要gpg簽名。
執行:
mvn clean deploy -P release
3.2.3登錄sonatype執行發佈操作
3.2.3.1登錄
https://oss.sonatype.org/#stagingRepositories
3.2.3.2驗證
查看你所提交的Repository。
勾選需要sonatype驗證的Repository,點擊菜單欄的Close。
在下方狀態欄中(Activity)可以看見sonatype正在執行驗證,並且會實時的顯示驗證結果
3.2.3.3發佈
當驗證完成後!
查看你所提交的Repository。
勾選需要sonatype發佈的Repository,點擊菜單欄的Release。
在下方狀態欄中(Activity)可以看見sonatype正在執行發佈,並且會實時的顯示驗證結果
3.2.3.4驗證
整個Repository消失後,表示發佈成功,可以在倉庫中找到了。
sonatype倉庫地址:
https://oss.sonatype.org/content/repositories/releases/
過一段時間後,中央倉庫會從sonatype倉庫同步。中央倉庫查看地址:
http://mvnrepository.com/