之前在github上開發(fā)了一個簡單的項目,一直想把這個jar包發(fā)布到中央倉庫态辛。一直沒有時間弄這個麸澜,今天抽出點時間,按照網(wǎng)上的例子奏黑,操作了一遍炊邦,順便記錄一下,一遍將來參考熟史。我的開發(fā)環(huán)境是ubuntu18.04馁害,maven3,整個過程還是比較順利的蹂匹。
注冊JIRA賬號
打開https://issues.sonatype.org/secure/Dashboard.jspa 碘菜,用郵箱注冊即可。
創(chuàng)建issue
需要填寫group id項目地址之類的限寞,頁面都有示例提示忍啸。
等待審核
提交的issue需要人工審核,審核之后履植,issue的狀態(tài)變?yōu)椋篟ESOLVED计雌,到了這一步就可以上傳jar包了。
配置maven Setting.xml文件
maven的Setting.xml文件可以在安裝路徑的conf目錄下静尼,也可以只修改當前用戶.m
目錄下,如果你的電腦是多賬戶共享的話传泊。在Settings.xml文件中鼠渺,找到<servers>
標簽,然后在標簽中增加如下配置:
<server>
<id>自行替換</id>
<username>替換成自己的JIRA賬號</username>
<password>替換成自己的JIRA賬號密碼</password>
</server>
id一般寫oss就行眷细。需要和pom文件中保持一致拦盹。
修改pom文件
我這次發(fā)布的pom文件內(nèi)容如下:
<?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>
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
<version>7</version>
</parent>
<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/heqiao2010</url>
<connection>https://github.com/heqiao2010/LunarCalendar.git</connection>
</scm>
<developers>
<developer>
<name>Joel Herb</name>
<email>he_qiao_2010@yeah.net</email>
<organization>heqiao2010</organization>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<groupId>com.github.heqiao2010</groupId>
<artifactId>lunar</artifactId>
<version>1.0</version>
<name>LunarCalendar</name>
<description>A Java implementation of Chinese lunar calendar. </description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG -->
<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>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>oss</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>oss</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>
生成并上傳密鑰
運行如下命令,根據(jù)提示生成密鑰溪椎,需要設(shè)置pharse普舆。
gpg --gen-key
生成的密鑰類似:
? ~ gpg --list-keys
/home/qiaohe/.gnupg/pubring.gpg
-------------------------------
pub rsa3072 2019-06-21 [SC] [有效至:2021-06-20]
812FAC0448CBA6C3E8EA8EA67BA82CF4A21310B2
uid [ 絕對 ] Joel Herb <he_qiao_2010@yeah.net>
sub rsa3072 2019-06-21 [E] [有效至:2021-06-20]
然后上傳密鑰:
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 812FAC0448CBA6C3E8EA8EA67BA82CF4A21310B2
執(zhí)行部署
mvn clean deploy -P release
-P命令用于指定pom文件中profile的id。在編譯之后校读,上傳到中央服務器的時候沼侣,系統(tǒng)會提示讓你輸入密鑰中的phrase,如果是windows系統(tǒng)可以在編譯命令后加上-Dgpg.passphrase=設(shè)置的pharse
上傳完成之后在https://oss.sonatype.org (登陸賬號和新建issue的賬號一致)這個頁面的staging repositories頁簽中可以看到剛才上傳的內(nèi)容歉秫,默認是open狀態(tài)的蛾洛,先點擊上方的close然后再點擊release即可。注意relesea版本的jar中的版本號不能帶SNAPSHOT字樣,因為SNAPSHOT版本是不穩(wěn)定版轧膘,不應該release钞螟,否則會有歧義,容易引起誤解谎碍。
通知管理員
在之前創(chuàng)建的issue下鳞滨,評論通知管理員,已經(jīng)上傳jar包了蟆淀。等管理員操作之后拯啦,在中央倉庫就可以看到上傳的jar包了。例如:
<dependency>
<groupId>com.github.heqiao2010</groupId>
<artifactId>lunar</artifactId>
<version>1.0</version>
</dependency>
參考
https://blog.csdn.net/ljbmxsm/article/details/78009268
轉(zhuǎn)自: http://heqiao2010.github.io