記錄一次發(fā)布jar包到maven中央倉庫的經(jīng)歷
1.注冊JIRA賬號
注冊地址:https://issues.sonatype.org/secure/Dashboard.jspa
注:這里密碼要設置規(guī)則有點麻煩俱两,看它的提示設置
2.創(chuàng)建 issue
注:這個里的groupId要和pom中的groupId一致(看別人寫的夺脾,沒證實過)
參考已經(jīng)審核通過的
這些都是要填寫的卒茬!Project URL 和SCM url 可以填寫自己github項目的地址
創(chuàng)建好以后 sonatype的工作人員審核處理焕议,速度還是很快的,一般一個工作日以內(nèi)就有回復
比如:
讓你驗證下是否是你自己填寫的冻河,一般有幾種方式原环,常用選擇第一種
- Add a TXT record to your DNS referencing this JIRA ticket:
OSSRH-54313(Fastest)
自己添加好DNS后坝锰,再次點擊回應按鈕,一般還是一個工作日內(nèi)會回復你:
這個就代表好了今魔,可以繼續(xù)操作了
3.配置maven Setting.xml文件
id要和pom中的id對應勺像,配置過私服的應該都知道
用戶名密碼是注冊jira的用戶名密碼
4.windows環(huán)境安裝gpg4win
下載地址:https://www.gpg4win.org/download.html
安裝成功后障贸,進入cmd,輸入命令:
gpg --gen-key
中間提示你要設置名字+郵箱吟宦,其他可以使用默認值篮洁,記住輸入的passphrase,后面mvn deploy會用到
5.上傳密鑰
上傳剛剛生成的秘鑰
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公鑰ID
常用gpg命令如下:
查看是否安裝成功
gpg --version
生成密鑰對
gpg --gen-key
查看公鑰
gpg --list-keys
將公鑰發(fā)布到PGP密鑰服務器
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公鑰ID
查詢公鑰是否發(fā)布成功
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 公鑰ID
下面是上傳好的效果圖
6.配置pom.xml(重點)
這里有好多坑殃姓,所以直接copy操作好的pom出來
<?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>ltd.vastchain</groupId>
<artifactId>vctc-java-sdk</artifactId>
<version>1.0.0</version>
<name>vctc-java-sdk</name>
<description>Official Java SDK for VastChain. https://www.vastchain.cn</description>
<url>https://github.com/vastchain/vctc-java-sdk</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<licenses>
<license>
<name>MIT License</name>
<url>https://github.com/everitoken/evt4j/blob/master/LICENSE</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>https://github.com/vastchain/vctc-java-sdk</url>
<connection>scm:git:git@github.com:vastchain/vctc-java-sdk</connection>
<developerConnection>scm:git:git@github.com:vastchain/vctc-java-sdk</developerConnection>
</scm>
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.58</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<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>false</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnError>false</failOnError>
<doclint>none</doclint>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</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>
</plugins>
</build>
<developers>
<developer>
<name>weihui</name>
<email>weihui@vastchain.ltd</email>
</developer>
</developers>
<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>
嚴格來說這些<licenses> <scm><>plugin都要配置袁波,甚至name,description,url都要配置
如果不配置,deploy的時候會報錯
之前遇到3類錯誤蜗侈,各種標簽missing锋叨,直接添加就好了
還有一種就是沒有公鑰,需要你重新上傳一次公鑰就好了宛篇,重新執(zhí)行命令
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公鑰ID
就可以了
第三個錯誤是javadoc 找不到娃磺,所以我這邊就配置了failOnError
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<failOnError>false</failOnError>
<doclint>none</doclint>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
7.maven deploy
和操作私服一樣
build過程中會讓你輸入之前填寫的passphrase
最后看到BUILD SUCCESS,就代表成功了叫倍,如果有錯誤偷卧,按照上面列的3種,解決掉再點一次deploy即可
8.發(fā)布到中央倉庫
登陸https://oss.sonatype.org/#stagingRepositories
用戶名密碼和注冊的jira賬號一樣
點擊release就ok了
坐等2小時等它自己同步到maven中央倉庫
jira那邊也回復了
不過我這邊是需要搜索下才顯示
https://search.maven.org
如果直接搜索這個搜不到吆倦,需要搜索上面那個鏈接訪問看看
注:如果沒有通過配置自動發(fā)布插件nexus-staging-maven-plugin听诸,進行mvn deploy,是看不到的蚕泽,而且需要手動drop掉晌梨,比如: