詳細描述maven中央倉庫發佈jar包的中間過程, 以及遇到的一些問題彙總, 儘量用文字描述清楚, 耐心看下去, 就一定會發布成功
----Sonatype篇----
名詞解釋:
Sonatype Nexus: Sonatype Nexus helps software development teams use open source so they can innovate faster and automatically control risk
maven社區唯一指定的倉庫地址為: https://search.maven.org/ 所以, 我們現在用的遠程倉庫地址, 無論是哪個, 都是需要去這個倉庫同步index的, 然後在把依賴同步到自己的倉庫下面
整個maven倉庫網絡是一個拓撲型架構, 倉庫與倉庫之間可以互相依賴, 且互相索引
如果想上傳jar到公服倉庫, 那麼首先要打通的就是sonatype, 我們首先去sonatype官網註冊個賬號, 訪問https://issues.sonatype.org/secure/Dashboard.jspa這個地址是sonatype
控制檯, 如果未登錄, 則會先跳轉到登錄界面, 點擊註冊, 填寫相關信息, 註冊個賬號然後登錄
1. 進入控制檯之後, 點擊新建按鈕, 新建一個問題(issue)
project 選擇community support -open source.... issue 選擇new project summary 填寫一些項目簡短描述 description 填寫項目的描述 group id 這個最重要了, 要與你的工程pom文件裡的頂級group id 一致, 而且這個是不能亂填的, 一般來說, 是你自己的域名反寫 Project URL 進入到你項目的url, 假如你的項目在github上, 先進到你的項目中, 然後複製地址欄上的地址填進去就可以 SCM url 同上, 但是這個url要填寫你的git資源下載地址, 就是項目右側的clone&download那個按鈕彈出來的地址 Username(s) 用戶名 Already Synced to Central 默認選NO就可以, 因為暫時我們還不需要同步到中央倉庫
2. 等待ISSUE審批, 一般來說, 2分鐘左右, 你就會收到審批結果(同時會給你的郵箱發郵件), 告訴你, 要驗證你的域名, 也就是你的
group id對應的域名, 會通過以下幾種方式驗證這個域名是不是你的 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
這個裡面告訴你, 最快的辦法就是在你的域名解析中, 添加一條text記錄, 我當時就是用的這種方式, 具體操作如下:
進入到域名商網站, 登錄之後選擇域名解析
點擊添加記錄, 記錄類型選擇text
主機記錄不要寫(默認是@)
記錄值寫你的問題編號
其他都不需要改, 點擊確定
如果填的沒問題的話, 大概10分鐘左右, 你就會收到審核通過的消息, 告訴你可以上傳資源了
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
他告訴你, 如果你提交了版本, 最好告訴他一下, 不用管, 以後我們也不會理他的
----GPG篇----
使用 GPG 生成密鑰對
Windows下載 Gpg4win 軟件來生成密鑰對, 地址:https://www.gpg4win.org/download.html
我用的mac, 使用brew安裝的gpg brew install gnupg
使用以下命令來生成祕鑰對:
$ gpg --gen-key #按照提示輸入信息, 在輸入密碼的時候, 如果嫌麻煩就直接摁回車就可以, 這樣祕鑰就沒有密碼保護了, 密碼保護只有在你的私鑰洩露的時候才有用, 其他時候沒用 $ gpg --list-keys #這個指令會顯示你的祕鑰環, 類似於下面這樣 #--------------------------------- # pub rsa4096 2018-09-25 [SC] # EABB59A7BFXXXXXX46604F95ED1503AA8CDxxxx (這個才是祕鑰ID) # uid [ 絕對 ] xxx (zhushi)
[zhang3221994 ] 如何把JAR發佈到maven中央倉庫的幾種方法已經有339次圍觀