編者按
???????? 筆者最近在github上開源了一個Excel格式文件解析工具 excel2javaBean , 應(yīng)要求上傳項(xiàng)目到Maven倉庫罐孝。其中坎坷不表, 現(xiàn)記錄上傳過程以供未來查閱。
目錄
一井誉、 注冊 Sonatype JIRA 用戶并創(chuàng)建工單
二贡歧、 安裝 GPG 并生成密鑰
三、 配置項(xiàng)目pom.xml和本地Maven setting.xml
四探膊、 部署杠愧、發(fā)布和查看
一、 注冊 Sonatype JIRA 用戶并創(chuàng)建工單
JIRA 用戶名和密碼后面(3.2)會用到
1.1 創(chuàng)建工單
最終點(diǎn)擊 Create 按鈕創(chuàng)建工單
對于第四步逞壁,雖然在創(chuàng)建Maven項(xiàng)目時可以隨意寫Group Id流济,但最好使用真實(shí)擁有的域名或推薦的com.github.[github用戶名]格式域名。
1.2 等待管理員回復(fù)
即使Group Id對應(yīng)的域名屬于你腌闯,也可能會質(zhì)詢绳瘟,回復(fù)擁有即可。由于我確實(shí)沒有申請域名guojy.com姿骏,所以選擇變更糖声。
二、 安裝 GPG 并通過命令生成密鑰
2.1 下載并安裝GPG并驗(yàn)證命令可用 windows版下載鏈接
2.2 生成密鑰并上傳公鑰到服務(wù)器
彈出窗口要求輸入的密語要記得, 后面(4.1)會用到
三姨丈、 配置項(xiàng)目pom.xml和本地 Maven setting.xml
3.1 配置項(xiàng)目的pom.xml文件
<!--這里以spring-cloud-gray為例-->
<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>
<tag>master</tag>
<url>git@github.com:SpringCloud/spring-cloud-gray.git</url>
<connection>scm:git:git@github.com:SpringCloud/spring-cloud-gray.git</connection>
<developerConnection>scm:git:git@github.com:SpringCloud/spring-cloud-gray.git</developerConnection>
</scm>
<developers>
<developer>
<name>saleson</name>
<email>qlichunyu@163.com</email>
<organization>Spring Cloud中國社區(qū)</organization>
</developer>
</developers>
<profiles>
<profile>
<id>sonatype-oss-release</id>
<build>
<plugins>
<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>
<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<!--對應(yīng)setting.xml servers.server.id-->
<id>sonatype-nexus-snapshots</id>
<url>
https://oss.sonatype.org/content/repositories/snapshots
</url>
</snapshotRepository>
<repository>
<!--對應(yīng)setting.xml servers.server.id-->
<id>sonatype-nexus-staging</id>
<url>
https://oss.sonatype.org/service/local/staging/deploy/maven2
</url>
</repository>
</distributionManagement>
</profile>
</profiles>
maven-gpg-plugin如果不易自動下載可以選擇使用命令
mvn dependency:get -DrepoUrl=http://repo.maven.apache.org/maven2/ -Dartifact=org.apache.maven.plugins:maven-gpg-plugin:1.1
手動下載畅卓。
3.2 配置本地maven的setting.xml文件
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>JIRA 用戶名</username>
<password>JIRA 用戶密碼</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>JIRA 用戶名</username>
<password>JIRA 用戶密碼</password>
</server>
</servers>
四、 部署蟋恬、發(fā)布翁潘、通知審批和查看
4.1 部署
mvn clean deploy -P -sonatype-oss-release -Darguments="gpg.passphrase=密語" -Dmaven.test.skip=true
命令執(zhí)行的過程中會要求在命令行和彈出框中輸入密語,輸入即可歼争;gpg會報(bào)warn拜马,直接忽略;到deploy階段沐绒,會上傳不少文件俩莽,耐心等待即可。
4.2 發(fā)布
nexus登陸地址乔遮,這里的用戶名和密碼和登陸jira的一樣扮超。
4.3 通知審批
收到回復(fù)后等待10分鐘左右即可完成同步Maven中央庫,同步到search.maven.org則需要2小時以上蹋肮;這一步只在首次部署發(fā)布時進(jìn)行出刷,之后的部署發(fā)布只需完成到4.2即可到4.4查看。