Java上傳java包到maven中央倉庫
最近閒著無聊,突然想到將自己做的jar包上傳Maven中央倉庫以供使用,就是閒著蛋疼,說幹就幹,查閱了無數資料,遇到不少坑,現將方法記錄下來以免以後忘記了,也就此機會重新學習下。
大致步驟:
3.配置pom.xml和settings檔案
4.部署jar包
一、建立工單
註冊不多說了,填完資訊下一步就是了!
第二步:建立Issue專案
點選頁面上的create,新建一個Issue
有*標記是必填的,其它可以不填,以下是填寫說明
summary:專案說明,能說明你的專案就行了
groupId:專案唯一標識,個人網站或公司網站域名倒寫,例如com.github.xinxiaomu
project URL:寫專案路徑,或個人主頁都可以
SCM URL:和專案路徑一樣就可以了
第三步:等待Issue通過
網上教程說,稽核要1~2天,我提交稽核的時候基本秒過的(可能它們遇到週末了吧,個人猜測哈哈),還有如果你groupId是個人或
公司的,會問你是否是你自己的域名,你回覆是就可以了,如果是用git這種開源的域名則不用,我使用的是git的網址,幾分鐘就通
過了,通過後會收到資訊:
二、GPG生成金鑰
第二步:生成金鑰
命令:gpg --full-generate-key 或gpg --gen-key
第三步:釋出公鑰到GPS key-servers
命令:gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 965310440A0AF2FD
三、 配置pom.xml和settings檔案
第一步:安裝maven
第二步:配置pom.xml
<?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和建立Issue時的一致,否則沒有許可權-->
<groupId>com.github.xinxiaomu</groupId>
<artifactId>swagger-ui-xin</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<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/xinxiaomu/swagger-ui</url>
<connection>scm:git:https://github.com/xinxiaomu/swagger-ui.git</connection>
<developerConnection>scm:git: [email protected]:xinxiaomu/swagger-ui.git</developerConnection>
</scm>
<developers>
<developer>
<name>hanxin</name>
<email>[email protected]</email>
<url>https://github.com/xinxiaomu</url>
</developer>
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<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>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<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>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<!--和settings中的一致-->
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<!--和settings中的一致-->
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</project>
第三步:配置settings.xml
檔案在maven目錄conf資料夾中,賬號和密碼是上面註冊JIRA的賬號和密碼
<servers>
<server>
<id>ossrh</id>
<username>賬號</username>
<password>密碼</password>
</server>
<server>
<id>ossrh</id>
<username>賬號</username>
<password>密碼</password>
</server>
</servers>
四、部署jar包
進入需要上傳的專案目錄,pom.xml所在目錄,執行命令:
mvn clean deploy或mvn clean deploy –P release –Dgpg.passphrse=xxxxx
選擇Staging Repositories ,並找到自己上傳的檔案。
找到後選中點選左上方的'close',並等待...等到通過後(狀態從open變為close,此時release按鈕變亮),點選release按鈕,
等待10分鐘左右就可以用了。
如果是第一次上傳,那麼需要在Issue中回覆才可以:
PS:不要忘記安裝JDK環境。
參考資料: