上傳項目到Maven中央倉庫

編者按

???????? 筆者最近在github上開源了一個Excel格式文件解析工具 excel2javaBean , 應要求上傳項目到Maven倉庫。其中坎坷不表, 現記錄上傳過程以供未來查閱。


目錄

一、 注冊 Sonatype JIRA 用戶并創(chuàng)建工單
二、 安裝 GPG 并生成密鑰
三、 配置項目pom.xml和本地Maven setting.xml
四、 部署、發(fā)布和查看

一、 注冊 Sonatype JIRA 用戶并創(chuàng)建工單

登陸Sonatype JIRA并注冊用戶

JIRA 用戶名和密碼后面(3.2)會用到

1.1 創(chuàng)建工單

創(chuàng)建工單

最終點擊 Create 按鈕創(chuàng)建工單

對于第四步,雖然在創(chuàng)建Maven項目時可以隨意寫Group Id,但最好使用真實擁有的域名或推薦的com.github.[github用戶名]格式域名。

1.2 等待管理員回復

等待管理員回復

即使Group Id對應的域名屬于你,也可能會質詢,回復擁有即可。由于我確實沒有申請域名guojy.com,所以選擇變更。

變更域名并獲得相關地址

二、 安裝 GPG 并通過命令生成密鑰

2.1 下載并安裝GPG并驗證命令可用 windows版下載鏈接

根據操作系統(tǒng)類型下載相應的GPG安裝包

gpg --version

2.2 生成密鑰并上傳公鑰到服務器

gpg --gen-key

彈出窗口要求輸入的密語要記得, 后面(4.1)會用到

gpg --gen-key2
gpg --keyserver

三、 配置項目pom.xml和本地 Maven setting.xml

3.1 配置項目的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>
                    <!--對應setting.xml servers.server.id-->
                    <id>sonatype-nexus-snapshots</id>
                    <url>
                        https://oss.sonatype.org/content/repositories/snapshots
                    </url>
                </snapshotRepository>
                <repository>
                    <!--對應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會報warn,直接忽略;到deploy階段,會上傳不少文件,耐心等待即可。

4.2 發(fā)布

登陸nexus

nexus登陸地址,這里的用戶名和密碼和登陸jira的一樣。

點擊close后填寫備注信息

release.JPG

4.3 通知審批

首次上傳通知審批.JPG

收到回復后等待10分鐘左右即可完成同步Maven中央庫,同步到search.maven.org則需要2小時以上;這一步只在首次部署發(fā)布時進行,之后的部署發(fā)布只需完成到4.2即可到4.4查看。

4.4 查看

release完成后可以查看上傳結果

在maven中央倉庫中查看上傳結果

在search.maven.org上查看上傳結果

引用

1. 發(fā)布jar包到maven中央庫

2. 將項目發(fā)布到 maven 中央倉庫踩過的坑

3. GPG入門

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容