做者:小傅哥
博客:https://bugstack.cn - 原創系列專題案例
html
沉澱、分享、成長,讓本身和他人都能有所收穫!😄
(19年12月)最近想基於Spring Boot作個開源共享項目,開發一個分佈式任務DcsSchedule中間件能夠把Schedule加強。那麼遇到一個問題但願把Jar包發包到Maven中央倉庫,這樣須要使用的用戶就能夠直接引入。java
內容 | 備註 | |
---|---|---|
1 | 申請Github賬號: https://github.com | 用於上傳開源代碼:https://github.com/fuzhengwei... |
2 | GPG生成密鑰工具: https://gpg4win.org/download.... | 在後續流程中下載安裝生成密鑰並上傳置服務器,本文使用的服務器是:hkp://keyserver.ubuntu.com:80 |
3 | 工單系統: https://issues.sonatype.org | 負責申請上傳資格及完成第一次上傳,後續更新不須要使用,至關於一個啓動裝置 |
4 | 構件倉庫: https://oss.sonatype.org | 上傳的jar包會先存放到這裏,在這裏進行 Release 後便可發佈到maven中央倉庫,也能夠本地設置自動發佈 |
5 | 鏡像倉庫: http://search.maven.org | 最終成功發佈的jar能夠在這裏搜到 |
6 | Maven倉庫:https://mvnrepository.com | 通過幾個小時耐心的等待會在Maven倉庫中搜到 |
7 | 阿里雲倉庫:https://maven.aliyun.com | 阿里雲的倉庫會同步的快一些 |
8 | 我的域名:https://bugstack.cn | 這裏主要用於工單資格驗證(Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-53637 (Fastest)) |
咱們須要一個GPG環境,用來對上傳的文件進行加密和簽名,保證你的jar包不被篡改git
1991年,程序員Phil Zimmermann爲了避開政府監視,開發了加密軟件PGP。這個軟件很是好用,迅速流傳開來,成了許多程序員的必備工具。可是,它是商業軟件,不能自由使用。因此,自由軟件基金會決定,開發一個PGP的替代品,取名爲GnuPG。這就是GPG的由來。
生成密鑰(可使用命令行生成,也能夠直接在操做界面生成)程序員
當建立完工單後,會收到信息反饋(國外與咱們有時間差,半夜的時候他們審覈的更快);github
```java Do you own the domain itstack.org? If so, please verify ownership via one of the following methods: Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-53637 (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.fuzhengwei or com.github.fuzhengwei Would you like to use a free managed security reporting service (recommended)? Put https://hackerone.com/central-security-project/reports/new as your project's security issue reporting URL. We'll take care of the rest. For more details on the Central Security Project, visit https://www.sonatype.com/central-security-project ``` ![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly91c2VyLWdvbGQtY2RuLnhpdHUuaW8vMjAxOS8xMi83LzE2ZWRmMGI3ZmZjYTAzZWM?x-oss-process=image/format,png)
配置域名驗證簽名;TXT 指向問題域:https://issues.sonatype.org/b...spring
![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly91c2VyLWdvbGQtY2RuLnhpdHUuaW8vMjAxOS8xMi83LzE2ZWRmMGI3ODc5YjIzNGQ?x-oss-process=image/format,png)
在域名驗證截圖,回覆到問題下,人工審覈會進行驗證處理apache
![](https://imgconvert.csdnimg.cn/aHR0cHM6Ly91c2VyLWdvbGQtY2RuLnhpdHUuaW8vMjAxOS8xMi83LzE2ZWRmMGI4MGI0NTFjOWU?x-oss-process=image/format,png)
驗證成功後,會收到郵件回覆,也能夠在issues看到{意思就說去發佈你的Jar吧寶貝,發佈完告訴我一下(來這裏回覆下,我就讓你用了)}ubuntu
org.itstack.middleware has been prepared, now user(s) fuzhengwei 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 * Release staged artifacts into repository 'Releases'
please comment on this ticket when you promoted your first release, thanks ```
接下來等待發布Jar包成功後,到這裏回覆並收到反饋,以下(證實你成功了!);設計模式
Central sync is activated for org.itstack.middleware. 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.
<server> <id>sonatype-nexus-snapshots</id> <username>https://issues.sonatype.org的帳號</username> <password>https://issues.sonatype.org的密碼</password> </server> <server> <id>sonatype-nexus-staging</id> <username>https://issues.sonatype.org的帳號</username> <password>https://issues.sonatype.org的密碼</password> </server> <server> <id>ossrh</id> <username>https://issues.sonatype.org的帳號</username> <password>https://issues.sonatype.org的密碼</password> </server>
<mirror> <id>alimavenrepository</id> <name>aliyun maven repository</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror>
<profile> <id>ossrh</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <gpg.executable>D:/Program Files (x86)/GnuPG/bin/gpg.exe</gpg.executable> <gpg.passphrase>上面生成的密鑰密碼:bugstack.cn</gpg.passphrase> <gpg.homedir>{找到dir:cmd->gpg --list-key}C:/Users/fuzhengwei/AppData/Roaming/gnupg</gpg.homedir> </properties> </profile>
<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> <url>https://github.com/fuzhengwei/schedule-spring-boot-starter</url> <connection>https://github.com/fuzhengwei/schedule-spring-boot-starter.git</connection> <developerConnection>https://github.com/fuzhengwei/schedule-spring-boot-starter</developerConnection> </scm> <developers> <developer> <name>fuzhengwei</name> <email>184172133@qq.com</email> <url>https://github.com/fuzhengwei/schedule-spring-boot-starter</url> </developer> </developers> <distributionManagement> <snapshotRepository> <id>ossrh</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement>
<!-- 發佈Jar到Maven倉庫 Begin --> <!--生成Source jar文件--> <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> <!--生成Javadoc,關閉doclint,避免註解檢查不經過--> <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> <configuration> <additionalparam>-Xdoclint:none</additionalparam> </configuration> </execution> </executions> </plugin> <!--Maven GPG插件用於使用如下配置對組件進行簽名--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId> <version>1.5</version> <executions> <execution> <id>sign-artifacts</id> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> <!--Nexus Staging Maven插件是將組件部署到OSSRH並將其發佈到Central Repository的推薦方法--> <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> <!-- 發佈Jar到Maven倉庫 End -->
到上面"配合人工審覈",按照說明提交發布成功信息,驗證成功後會收到回覆,以下;服務器
Central sync is activated for org.itstack.middleware. 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.