上傳jar包到maven中央倉庫遇到的坑

最近寫了個nebula集成到springboot的starter,想把它給上傳到maven中央倉庫,方便有需要的人可以下載使用,就找了些網上資料,折騰了半天好不容易給上傳上去了,下面說一下整個流程及遇到的坑。

首先我們要去https://issues.sonatype.org/secure/Signup!default.jspa 這個網站先註冊個賬號,這個就是個jira應用,開發的同學應該多少接觸過。

 

註冊這裏大家百度,就不說了,登陸系統以後,我們要創建一個issue,主要目的是完成平臺審覈的一個流程,完成這個流程以後,你纔有權限把自己的jar包上傳到maven中央倉庫

 

項目選擇 Community Support - Open Source Project Repository Hosting,問題類型是 New Project,概要可以隨便填寫

 

這幾個必填項比較關鍵,首先是group id,填寫的是根據你的倉庫地址的域名得來的,如果倉庫地址是 https://gitee.com/xxx 則group id 是com.gitee.xxx,如果是github的地址 https://github.com/xxx 則是 com.github.xxx

Project URL是你需要上傳的項目地址,SCM url是項目的git地址,創建完就會生成一個issue

 

然後就是等管理員審覈了

 

中間審覈狀態會變化,會需要裏在自己的域名下面創建一個指定名稱的倉庫,按照要求的創建好以後,你可以按我上面的回覆一下,審覈通過的話,你就會收到一條新的恢復,告訴你權限已經開通了,可以按照鏈接裏的指導內容進行上傳jar了,這裏建議還是看一下鏈接裏面的內容進行操作,我之前因爲參考了別人寫的指導手冊,導致遇到了一些坑,網上的指導手冊有些內容與現在的最新官方指導有些變化。

 

首先是紅框裏面的內容,網上現有的教程都是使用的 https://oss.sonatype.org/ 這個鏈接,你用這個鏈接的時候,最後上傳的時候會發現提示你沒有權限,開始我也是沒看官方文檔,搞了半天沒明白咋回事,也就是新創建的項目使用的是https://s01.oss.sonatype.org 這個新地址,老的項目其實還是可以用原來的地址,這個大家一定要注意。

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>com.gitee.dushougudu</groupId>
    <artifactId>nebula-spring-boot-starter</artifactId>
    <version>1.0.0</version>
    <name>nebula-spring-boot-starter</name>
    <packaging>jar</packaging>
    <description>NEBULA-SDK</description>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <com.vesoft.client>2.0.0</com.vesoft.client>
        <neo4j-cypher-dsl>2021.2.2</neo4j-cypher-dsl>
        <druid>1.2.4</druid>
        <guava>30.1.1-jre</guava>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.0</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>
        <tag>master</tag>
        <url>[email protected]:snowheart/dingtalk-robot.git</url>
        <connection>scm:git:[email protected]:dushougudu/nebula-spring-boot-starter.git</connection>
        <developerConnection>scm:git:[email protected]/dushougudu/nebula-spring-boot-starter</developerConnection>
    </scm>
    <developers>
        <developer>
            <name>Morgan Zhang</name>
            <email>[email protected]</email>
            <organization>dushougudu</organization>
        </developer>
    </developers>

    <dependencies>
        <dependency>
            <groupId>com.vesoft</groupId>
            <artifactId>client</artifactId>
            <version>${com.vesoft.client}</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-log4j12</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j-cypher-dsl</artifactId>
            <version>${neo4j-cypher-dsl}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>${druid}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.20</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>30.1.1-jre</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>release</id>
            <distributionManagement>
                <snapshotRepository>
                    <id>ossrh</id>
                    <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
                </snapshotRepository>
                <repository>
                    <id>ossrh</id>
                    <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>
            <build>
                <plugins>
                    <!--java source生成插件-->
                    <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>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <configuration>
                                    <additionalparam>-Xdoclint:none</additionalparam>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!--gpg簽名插件-->
                    <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>

                    <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://s01.oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </profile>
    </profiles>

</project>

還有一個就是需要簽名,我是直接使用gitbash生成的密鑰,通過命令 gpg --gen-key  按照提示生成密鑰,然後把公鑰發佈到PGP 密鑰服務器:gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公鑰ID ,查詢公鑰是否發佈成功:gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 公鑰ID

生成密鑰以後我們就可以開始上傳了,執行上傳命令: mvn clean deploy -P release

但是執行的時候,總是提示找不到我的密鑰地址,我們可以通過 gpg --list-keys 查看自己的密鑰文件路徑,然後pom裏通過指定路徑就可以了

<properties>
        <gpg.homedir>gpg路徑</gpg.homedir>
 </properties>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章