第一次釋出jar包到maven中央倉庫
1.github上上傳專案(略)
2.在sonatype上註冊賬號
https://issues.sonatype.org/secure/Dashboard.jspa
注意記住使用者名稱和密碼
3.在sonatype建立問題
4.新建完後客服會給提示
主要是要求:groupId要合理,需要按照要求在github上建立空倉庫,做完這些後,然後修改狀態為開啟即可。
5.稽核成功後會發郵件通知,狀態顯示為已解決
6.專案修改groupId為上方指定的groupId
7.修改maven的setting.xml配置
<servers> <server> <id>ossrh</id> <username>sonatype使用者名稱</username> <password>sonatype登入密碼</password> </server> </servers>
8.修改pom.xml配置
<!-- 部署配置 --> <distributionManagement> <snapshotRepository> <id>ossrh</id> <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> </snapshotRepository> <repository> <id>ossrh</id> <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository> </distributionManagement>
9. 打包上傳
mvn clean install
mvn deploy
10.在倉庫上檢視快照版的jar包是否上傳成功
開啟:https://s01.oss.sonatype.org/
11.釋出正式版
批量修改版本號:
mvn versions:set -DnewVersion=1.0.0
部署:
mvn clean deploy
12.在sonatype上檢視暫存版
13.解決問題後放開進一步釋出到正式版
主要要解決檔案簽名問題,給檔案生成簽名檔案
下載gpg4win: https://www.gpg4win.org/download.html
安裝後,生成證書,釋出到伺服器等
參考:https://blog.csdn.net/ooyyaa6561/article/details/124900977
14.gpg相關配置
setting.xml配置
<profile> <id>ossrh</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <gpg.executable>gpg</gpg.executable> <gpg.passphrase>密碼</gpg.passphrase> </properties> </profile>
pom.xml配置
<profiles> <profile> <id>release</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <id>attach-sources</id> <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> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <version>3.0.1</version> <executions> <execution> <id>sign-artifacts</id> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
15. 執行打包部署命令
指定release這個profile執行
打包
mvn clean install -P release
部署
mvn clean deploy -P release
16. 及時釋出
close後,會給問題反饋,沒問題後,點選Release
17.jar包拉取驗證
快照版本:在pom.xml中新增以下倉庫
<repositories> <repository> <id>nexues</id> <name>snapshots</name> <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories>
然後新增maven依賴配置
正式版驗證:
待驗證。。。
遇到的問題:
gpg外掛無法執行
解決:1.安裝完gpg4win後需要重啟電腦,切記 2. setting.xml中的命令可能是gpg而非gpg2