參考博客:將組件發布到maven中央倉庫-CSDN博客?感謝這位博主。但是他的步驟有漏缺,相對進行補充
訪問管理頁面
網址:Maven Central
新注冊賬號,或者使用github快捷登錄,建議使用github快捷登錄
添加命名空間
注意,如果使用github快捷登錄,默認攜帶 io.github.?? 的命名空間,如果自己的代碼在github上,可以直接使用這個命名空間
如果代碼在 碼云 倉庫,
提交后,提示需要驗證空間,需要按照要求,到 碼云 倉庫創建一個對應名稱的空內容的項目,然后點擊認證。
如上圖, io.gitee.wsitm 是我的命名空間
添加其他命名空間見 Register a Namespace - The Central Repository Documentation
創建代碼倉庫
注意:代碼一定需要符合開源,可以使用MIT開源,或其他開源。創建開源極為容易,gitee默認會提示創建開源,有快捷入口,點擊快速創建。
代碼的pom.xml的配置
具體如下:
<?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>io.gitee.wsitm</groupId><artifactId>wsitm-clutter</artifactId><version>0.0.1</version><url>https://gitee.com/wsitm/wsitm-clutter.git</url><packaging>jar</packaging><name>${project.artifactId}</name><description>wsitm-clutter雜燴工具</description><dependencies></dependencies><licenses><license><name>MIT License</name><url>https://opensource.org/licenses/MIT</url><comments>The project itself is licensed under MIT License.</comments></license></licenses><developers><developer><name>yourname</name><email>youremail@qq.com</email></developer></developers><scm><connection>scm:git@gitee.com:wsitm/wsitm-clutter.git</connection><developerConnection>scm:git@gitee.com:wsitm/wsitm-clutter.git</developerConnection><url>https://gitee.com/wsitm/wsitm-clutter.git</url></scm><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>3.3.0</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><configuration><aggregate>true</aggregate><charset>UTF-8</charset><encoding>UTF-8</encoding><docencoding>UTF-8</docencoding><additionalparam>-Xdoclint:none</additionalparam></configuration><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.1.0</version><executions><execution><id>sign-artifacts</id><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin><!--maven插件--><plugin><groupId>org.sonatype.central</groupId><artifactId>central-publishing-maven-plugin</artifactId><version>0.4.0</version><extensions>true</extensions><configuration><publishingServerId>central</publishingServerId><tokenAuth>true</tokenAuth></configuration></plugin></plugins></build>
</project>
生成GPG密鑰
作用:這是用于給自身源碼加簽名
下載GPG管理軟件:https://gnupg.org/download/index.html
點擊進入下載頁面
如上圖,當然,如果有錢也可以捐獻一些。我不一樣,我白嫖
安裝完成之后,使用命令生成密鑰,命令:? gpg –gen-key
生成之后
推送密鑰到遠程服務端
命令:? gpg --keyserver hkp://keyserver.ubuntu.com --send-keys [生成密鑰后的標識]
例子:gpg --keyserver hkp://keyserver.ubuntu.com --send-keys 2*************F6449
服務:--keyserver 有三個官方網址可以切換
- keyserver.ubuntu.com
- keys.openpgp.org
- pgp.mit.edu
注意:可能推送不成功,三個網址我都測試不成功,不知道什么原因,只能使用另一種方法
公鑰如下:
復制全部內容,手動上傳,打開服務網址:? https://keyserver.ubuntu.com/#
生成token
得到的token格式如下:
maven的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"><servers><server><id>central</id><username>${tokenId}</username><password>${tokenPass}</password></server></servers><profiles><profile><id>gpg</id><properties><gpg.executable>gpg</gpg.executable><gpg.keyname>youremail@qq.com</gpg.keyname><gpg.passphrase>${pgp-password}</gpg.passphrase><gpg.useagent>true</gpg.useagent></properties></profile></profiles>
</settings>
發布到倉庫
進入代碼目錄,執行命令:? mvn clean deploy
發布完成,打開管理頁面
提交后需要驗證,如果正常
如果異常,查看錯誤描述
去倉庫查看自己的項目
阿里云:? 倉庫服務
官方:? Central Repository:
官方頁面:https://mvnrepository.com/
注:阿里云,和官方能在審核后1小時內能查到自己的項目,但是官方頁面需要好多天才能查詢。但直接在maven中引用即可,并不影響使用