如何把JAR發(fā)布到maven中央倉(cāng)庫(kù)的幾種方法
詳細(xì)描述maven中央倉(cāng)庫(kù)發(fā)布jar包的中間過程, 以及遇到的一些問題匯總, 盡量用文字描述清楚, 耐心看下去, 就一定會(huì)發(fā)布成功
----Sonatype篇----
名詞解釋:
Sonatype Nexus: Sonatype Nexus helps software development teams use open source so they can innovate faster and automatically control risk
maven社區(qū)唯一指定的倉(cāng)庫(kù)地址為: https://search.maven.org/ 所以, 我們現(xiàn)在用的遠(yuǎn)程倉(cāng)庫(kù)地址, 無論是哪個(gè), 都是需要去這個(gè)倉(cāng)庫(kù)同步index的, 然后在把依賴同步到自己的倉(cāng)庫(kù)下面
整個(gè)maven倉(cāng)庫(kù)網(wǎng)絡(luò)是一個(gè)拓?fù)湫图軜?gòu), 倉(cāng)庫(kù)與倉(cāng)庫(kù)之間可以互相依賴, 且互相索引
如果想上傳jar到公服倉(cāng)庫(kù), 那么首先要打通的就是sonatype, 我們首先去sonatype官網(wǎng)注冊(cè)個(gè)賬號(hào), 訪問https://issues.sonatype.org/secure/Dashboard.jspa這個(gè)地址是sonatype
控制臺(tái), 如果未登錄, 則會(huì)先跳轉(zhuǎn)到登錄界面, 點(diǎn)擊注冊(cè), 填寫相關(guān)信息, 注冊(cè)個(gè)賬號(hào)然后登錄
1. 進(jìn)入控制臺(tái)之后, 點(diǎn)擊新建按鈕, 新建一個(gè)問題(issue)
project 選擇community support -open source.... issue 選擇new project summary 填寫一些項(xiàng)目簡(jiǎn)短描述 description 填寫項(xiàng)目的描述 group id 這個(gè)最重要了, 要與你的工程pom文件里的頂級(jí)group id 一致, 而且這個(gè)是不能亂填的, 一般來說, 是你自己的域名反寫 Project URL 進(jìn)入到你項(xiàng)目的url, 假如你的項(xiàng)目在github上, 先進(jìn)到你的項(xiàng)目中, 然后復(fù)制地址欄上的地址填進(jìn)去就可以 SCM url 同上, 但是這個(gè)url要填寫你的git資源下載地址, 就是項(xiàng)目右側(cè)的clone&download那個(gè)按鈕彈出來的地址 Username(s) 用戶名 Already Synced to Central 默認(rèn)選NO就可以, 因?yàn)闀簳r(shí)我們還不需要同步到中央倉(cāng)庫(kù)
2. 等待ISSUE審批, 一般來說, 2分鐘左右, 你就會(huì)收到審批結(jié)果(同時(shí)會(huì)給你的郵箱發(fā)郵件), 告訴你, 要驗(yàn)證你的域名, 也就是你的
group id對(duì)應(yīng)的域名, 會(huì)通過以下幾種方式驗(yàn)證這個(gè)域名是不是你的 Central OSSRH updated OSSRH-xxxxx: ---------------------------------- Status: Waiting for Response (was: Open) Do you own the domain gomyck.com? If so, please verify ownership via one of the following methods: * Add a TXT record to your DNS referencing this issue (Fastest) * Setup a redirect to your Github page (if it does not already exist) * Send an email to central@sonatype.com referencing this issue from a gomyck.com email address If you do not own this domain, please read: http://central.sonatype.org/pages/choosing-your-coordinates.html You may also choose a groupId that reflects your project hosting, in this case, something like
這個(gè)里面告訴你, 最快的辦法就是在你的域名解析中, 添加一條text記錄, 我當(dāng)時(shí)就是用的這種方式, 具體操作如下:
- 進(jìn)入到域名商網(wǎng)站, 登錄之后選擇域名解析
- 點(diǎn)擊添加記錄, 記錄類型選擇text
- 主機(jī)記錄不要寫(默認(rèn)是@)
- 記錄值寫你的問題編號(hào)
- 其他都不需要改, 點(diǎn)擊確定
如果填的沒問題的話, 大概10分鐘左右, 你就會(huì)收到審核通過的消息, 告訴你可以上傳資源了
com.gomyck has been prepared, now user(s) gomyck,mzxc 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
他告訴你, 如果你提交了版本, 最好告訴他一下, 不用管, 以后我們也不會(huì)理他的
----GPG篇----
使用 GPG 生成密鑰對(duì)
Windows下載 Gpg4win 軟件來生成密鑰對(duì), 地址:https://www.gpg4win.org/download.html
我用的mac, 使用brew安裝的gpg brew install gnupg
使用以下命令來生成秘鑰對(duì):
$ gpg --gen-key #按照提示輸入信息, 在輸入密碼的時(shí)候, 如果嫌麻煩就直接摁回車就可以, 這樣秘鑰就沒有密碼保護(hù)了, 密碼保護(hù)只有在你的私鑰泄露的時(shí)候才有用, 其他時(shí)候沒用 $ gpg --list-keys #這個(gè)指令會(huì)顯示你的秘鑰環(huán), 類似于下面這樣 #--------------------------------- # pub rsa4096 2018-09-25 [SC] # EABB59A7BFXXXXXX46604F95ED1503AA8CDxxxx (這個(gè)才是秘鑰ID) # uid [ 絕對(duì) ] xxx (zhushi) <xxx@163.com> # sub rsa4096 2018-09-25 [E] $ gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 秘鑰ID #發(fā)送你的公鑰到秘鑰倉(cāng)庫(kù), 以后你的jar會(huì)使用私鑰簽名, maven中央倉(cāng)庫(kù)會(huì)去幾個(gè)指定的秘鑰倉(cāng)庫(kù)去找公鑰來驗(yàn)證這個(gè)簽名, 如果不上傳是不能通過審核的 $ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 秘鑰ID #驗(yàn)證你的公鑰是否上傳成功, 如果返回結(jié)果是 **未改變, 那就是成功了
----maven篇----
在你的maven頂級(jí)工程中加入以下配置
<groupId>com.gomyck</groupId>
<artifactId>gomyck-quickdev</artifactId>
<packaging>pom</packaging>
<version>1.1.0-SNAPSHOT</version>
<name>gomyck-quickdev</name>
<url>http://www.gomyck.com</url>
<description>gomyck 快速開發(fā)平臺(tái)</description>
<developers>
<developer>
<id>gomyck</id>
<name>haoy</name>
<url>www.gomyck.com</url>
<email>hao474798383@163.com</email>
</developer>
</developers>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<connection>scm:git:git@github.com:mzxc/gomyck-fastdfs-spring-boot-starter.git</connection>
<developerConnection>scm:git:git@github.com:mzxc/gomyck-fastdfs-spring-boot-starter.git</developerConnection>
<url>git@github.com:mzxc/gomyck-fastdfs-spring-boot-starter.git</url>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</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>
<configuration>
<!-- 你的秘鑰ID -->
<keyname>${gpg.keyname}</keyname>
<passphraseServerId>${gpg.keyname}</passphraseServerId>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>sonatype-nexus-staging</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
在你的settings.xml中加入以下配置
<server>
<id>sonatype-nexus-snapshots</id>
<username>sonatype賬號(hào)</username>
<password>sonatype密碼</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>sonatype賬號(hào)</username>
<password>sonatype密碼</password>
</server>
<profiles>
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.keyname>你的秘鑰 ID</gpg.keyname>
</properties>
</profile>
</profiles>
運(yùn)行deploy, 如果按照我的步驟一步一步走, 應(yīng)該沒有錯(cuò)誤(如果報(bào)錯(cuò)也是你的doc問題, 按照提示一步一步改好, 否則maven審核會(huì)失敗)
----nexus篇----
如果上一步?jīng)]有錯(cuò)誤的話, 訪問網(wǎng)址: https://oss.sonatype.org/#stagingRepositories
點(diǎn)擊右上角登錄, 賬號(hào)密碼就是sonatype的賬號(hào)密碼, 登錄進(jìn)去之后, 點(diǎn)擊Staging repositories
在右側(cè)搜索框輸入你的group id, 然后點(diǎn)擊refresh, 就會(huì)看到你的提交信息
選中, 點(diǎn)擊close, 這時(shí)當(dāng)前的紀(jì)錄就會(huì)變成一個(gè)小齒輪, 表示nexus在校驗(yàn)?zāi)愕膉ar
按照劇本, 你的提交應(yīng)該會(huì)全部通過(圖標(biāo)顯示數(shù)字就是失敗, 反之則是成功)
再次選中當(dāng)前記錄, 點(diǎn)擊release, 就會(huì)上傳成功了, 這時(shí)sonatype會(huì)給你發(fā)郵件
以后你只需要按照maven篇deploy, 然后在使用nexus篇提交release就可以了
注意: 如果是snapshot版本, 則不需要審核, 直接deploy就可以直接引用, 但是在maven倉(cāng)庫(kù)(https://search.maven.org/)是搜索不到的
----爬坑篇----
1.一開始總是提示文件驗(yàn)證簽名失敗, 提示我說沒有在秘鑰倉(cāng)庫(kù)找到對(duì)應(yīng)的公鑰, 但是我本地可以確定的是提交了且ID一致, 后來過了大概1小時(shí), 驗(yàn)證忽然就過了,
這期間, 我把nexus提示的秘鑰倉(cāng)庫(kù)地址都復(fù)制出來, 挨個(gè)上傳我的公鑰, 最后不知道是哪個(gè)倉(cāng)庫(kù)生效了, 但是我覺得是倉(cāng)庫(kù)延遲問題
2.以后寫代碼一定要把doc寫好, 不然遇見這種場(chǎng)景, 簡(jiǎn)直就是折磨, 尤其doc多的時(shí)候
3.如果你有多個(gè)gpg秘鑰, 一定要指定秘鑰ID, 不然gpg插件是秘鑰環(huán)的順序來對(duì)你的工程簽名的, 這會(huì)導(dǎo)致你上傳的公鑰不一定對(duì)應(yīng)的上簽名的私鑰, 秘鑰的ID請(qǐng)?jiān)趕ettings.xml中配置profile, gpg插件的配置請(qǐng)到apache-gpg官網(wǎng)看
4.sonatype在國(guó)內(nèi)環(huán)境下, 訪問非常困難, 建議找個(gè)科學(xué)上網(wǎng)的方式, 來實(shí)踐本教程
到此這篇關(guān)于如何把JAR發(fā)布到maven中央倉(cāng)庫(kù)的幾種方法的文章就介紹到這了,更多相關(guān)JAR發(fā)布到maven中央倉(cāng)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java Mail郵件發(fā)送如何實(shí)現(xiàn)簡(jiǎn)單封裝
這篇文章主要介紹了Java Mail郵件發(fā)送如何實(shí)現(xiàn)簡(jiǎn)單封裝,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11
SpringBoot實(shí)現(xiàn)國(guó)密SM4加密解密的使用示例
在商用密碼體系中,SM4主要用于數(shù)據(jù)加密,本文就來介紹一下SpringBoot實(shí)現(xiàn)國(guó)密SM4加密解密的使用示例,具有一定的參考價(jià)值,感興趣的可以了解一下2023-10-10
MybatisPlus使用queryWrapper如何實(shí)現(xiàn)復(fù)雜查詢
這篇文章主要介紹了MybatisPlus使用queryWrapper如何實(shí)現(xiàn)復(fù)雜查詢,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。2022-01-01
spring boot+spring cache實(shí)現(xiàn)兩級(jí)緩存(redis+caffeine)
這篇文章主要介紹了spring boot+spring cache實(shí)現(xiàn)兩級(jí)緩存(redis+caffeine),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02
IDEA創(chuàng)建Java Web項(xiàng)目不能及時(shí)刷新HTML或JSP頁(yè)面問題
這篇文章主要介紹了IDEA創(chuàng)建Java Web項(xiàng)目不能及時(shí)刷新HTML或JSP頁(yè)面問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03
Java中的synchronized?優(yōu)化方法之鎖膨脹機(jī)制
這篇文章主要介紹了Java中的synchronized?優(yōu)化方法之鎖膨脹機(jī)制,鎖膨脹機(jī)制是提升?synchronized?性能最有利的方法之一,下面我們就來看看什么事鎖膨脹及鎖膨脹的各種細(xì)節(jié)2022-05-05

