歡迎關注個人博客:http://www.mydlq.clubhtml
最新寫了個開源項目,考慮到發佈到 Maven 中央倉庫實踐一下,想一想發佈成功的話只要有 Maven 的地方就能拉取,不存在 Jar 包不在沒法下載的問題。因爲第一次將項目提交到 Maven 中央倉庫,網上知識良莠不齊到最後碰見了不少坑,這裏記錄一下這個實踐過程。前端
在 GitHub 上新建一個項目倉庫,而後將要發送到 Maven 中央倉庫的代碼推送到 Github。這方面資料較多,這裏不過多敘述。java
進入 https://issues.sonatype.org/secure/Dashboard.jspa 註冊JIRA帳號,按提示完善我的信息。git
登陸 https://issues.sonatype.org/secure/Dashboard.jspa ,點擊建立按鈕來建立一個新的 issues 工單github
內容以下,填寫必填部分便可,而後等待審覈。web
等待一段時間就會收到一封郵件,內容以下:spring
[ https://issues.sonatype.org/browse/OSSRH-48958?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Central OSSRH 更新了 OSSRH-48958: ------------------------------ 狀態: Waiting for Response (原值: 開放) Do you own the domain mydlq.club? If so, please verify ownership via one of the following methods: * Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-48958 (Fastest) * Setup a redirect to your Github page (if it does not already exist) 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 io.github.my-dlq or com.github.my-dlq Swagger Kubernetes is a program for document aggregation of Swagger standardized service apis in a Kubernetes cluster. ---------------------------------------------------------------------------------------------------------------------- 關鍵字: OSSRH-48958 URL: https://issues.sonatype.org/browse/OSSRH-48958 項目: Community Support - Open Source Project Repository Hosting 問題類型: New Project 報告人: mydlq 經辦人: Joel Orlina 優先級: 重要 Swagger Kubernetes is a program for document aggregation of Swagger standardized service apis in a Kubernetes cluster. Service discovery under a Namespace of Kubernetes can be automatically performed. The interface of the Swagger API specification will be integrated and filtered. The service will be delegated to the service by zuul reverse proxy, and the Swagger API information will be aggregated and displayed by the Swagger UI.
意思就是詢問你該 GroupId 設置的域名是否爲你本身所擁有,若是是就須要證實一下,兩種方法apache
因爲本人有本身的域名,因此設置使用了第二種方法添加 NDS 解析記錄,這裏添加了記錄爲 OSSRH-48958,類型爲 TxT,值爲 https://issues.sonatype.org/browse/OSSRH-48958 的一條解析記錄信息。ubuntu
而後打開郵件中提到的地址 https://issues.sonatype.org/browse/OSSRH-48958 進入該 issues,在裏面回覆本身擁有該域名,且設置了 DNS 解析。api
打開 https://www.gpg4win.org/ 下載 GPG,而後一步步安裝。
安裝完成後會看到桌面上多了個 Kleopatra 圖標,這個程序是 GnuPG 的前端程序,這裏咱們將它打開。
打開 Kleopatra 後,點擊新建密鑰對
輸入姓名和郵箱
最後確認新建
過程當中須要本身輸入一個8位以上的密碼,請記住該密碼,後面還須要用到。 輸入完成之後就會提示下面信息。
打開命令提示符窗口,輸入下面命令將證書發送到遠程服務器
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 243EFB60D8F930B391CA194EA40663B00BDC6CA1
要想將項目發送到 Maven 中央倉庫,須要對項目進行一些設置來符合發佈條件。
配置 maven 目錄 conf 文件夾中的 settings.xml 文件,設置一個 server,裏面添加 JIRA 的帳號和密碼。
<servers> <server> <id>ossrh</id> <username>JIRA帳號</username> <password>JIRA密碼</password> </server> </servers>
Pom.xml 配置一些必要的信息,例如 Maven 文檔插件、打包插件、GPG驗證插件等,以下:
> 能夠查看個人項目的 GitHub 地址: https://github.com/my-dlq/swagger-kubernetes-maven ,pom 參數照着修改便可,順便點下 Start 星,Thanks。
<!--?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>club.mydlq</groupid> <artifactid>swagger-kubernetes</artifactid> <version>2.1.0</version> <packaging>jar</packaging> <name>swagger-kubernetes</name> <url>https://github.com/my-dlq/swagger-kubernetes</url> <description>swagger api doc for kubernetes discovery.</description> <!--licenses信息--> <licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>repo</distribution> </license> </licenses> <!--scm信息--> <scm> <url>http://mydlq.club</url> <connection>scm:git:https://github.com/my-dlq/swagger-kubernetes.git</connection> <developerconnection>scm:git:https://github.com/my-dlq/swagger-kubernetes.git</developerconnection> </scm> <!--發佈者信息--> <developers> <developer> <name>mydlq</name> <email>mynamedlq@163.com</email> <organization>http://mydlq.club</organization> <organizationurl>http://mydlq.club</organizationurl> </developer> </developers> <properties> <java.version>1.8</java.version> <project.build.sourceencoding>UTF-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> <version>2.1.0.RELEASE<</version> </dependency> </dependencies> <build> <plugins> <!-- doc plugin,Maven API文檔生成插件 --> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-javadoc-plugin</artifactid> <version>3.1.0</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <!-- resources plugin,Maven 資源插件 --> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-source-plugin</artifactid> <version>3.1.0</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin> <!-- compiler plugin,Maven 編譯插件 --> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.3</version> <configuration> <source>${java.version} <target>${java.version}</target> <showwarnings>true</showwarnings> </configuration> </plugin> <!-- gpg plugin,用於簽名認證 --> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-gpg-plugin</artifactid> <version>1.6</version> <executions> <execution> <id>sign-artifacts</id> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> <!--staging puglin,用於自動執行發佈階段(免手動)--> <plugin> <groupid>org.sonatype.plugins</groupid> <artifactid>nexus-staging-maven-plugin</artifactid> <version>1.6.7</version> <extensions>true</extensions> <configuration> <serverid>ossrh</serverid> <nexusurl>https://oss.sonatype.org/</nexusurl> <autoreleaseafterclose>true</autoreleaseafterclose> </configuration> </plugin> <!-- release plugin,用於發佈到release倉庫部署插件 --> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-release-plugin</artifactid> <version>2.4.2</version> </plugin> </plugins> </build> <!-- 這裏引入 Settings.xml 中設置的用戶名、密碼 --> <distributionmanagement> <snapshotrepository> <id>ossrh</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </snapshotrepository> <repository> <id>ossrh</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository> </distributionmanagement> </project>
若是Maven編譯doc因編碼緣由出錯,能夠在環境變量設置變量 JAVA_TOOL_OPTIONS,值爲 UTF-8 來改變編碼方式。
在發佈以前要求必須有登陸 Nexus Repositories 的信息,因此發佈前提早登陸 Nexus Repositories
登陸 https://oss.sonatype.org 其中用戶名、密碼就是 JIRA 的用戶名、密碼。
執行 maven 命令,部署項目到 Maven 倉庫,過程當中須要輸入以前設置的 GPG 密碼,輸入一下便可。
$ mvn clean deploy
回到 Nexus Repositories Manager,選擇 Staging Repositories 暫存庫,根據發佈時間查找到你提交的 Jar 信息。而後查看 Actives 裏面的執行信息,注意執行部署過程如今流行都交給 Maven 自動部署插件執行,網上一些老辦法是進入這裏面手動執行,很是不推薦這樣作,由於這樣很是容易部署發生問題。
> 注意: 在 Maven 執行發佈過程當中才能看到,若是已經 release 完成,暫存庫中可能找不到。
正常的部署流程應該爲:open階段—>close階段—>release階段 執行完成這三個階段就會發布到中央倉庫,等會會受到郵件通知
[ https://issues.sonatype.org/browse/OSSRH-48958?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Central OSSRH 更新了 OSSRH-48958: ------------------------------ Central sync is activated for club.mydlq. After you successfully release, your component will be published to Central, typically within 10 minutes, though updates to search.maven.org can take up to two hours.
意思爲 Release 成功,大概等十分鐘或者幾個就能在中央倉庫查詢到該 Jar 信息,不過對search.maven.org的更新可能須要兩個小時。
打開以前提交 Issues 地址,後面回覆已經 Release 完成
發佈成功後能夠進入 https://search.maven.org 網址查詢本身發佈的 Jar,若是未查到等幾個小時再此查詢。
歡迎關注個人博客:http://www.mydlq.club