maven發(fā)布jar包至nexus新版?zhèn)}庫(PGP密鑰模式)

準(zhǔn)備:

1-2.png

根據(jù)提示生成即可。


1-1.png
1-3.png
1-4.png
1-5.png
  • 注冊sonatype帳號,上傳jar包認(rèn)證帳號就是此帳號,注冊地址:https://issues.sonatype.org/。
  • 開通sonatype權(quán)限,按下面圖片中的步驟即可:
    1.jpg
2.png
3.png
4.png
  • 配置pom.xml,采用的是apache maven默認(rèn)插件打包上傳,非nexus倉庫的nexus-staging-maven-plugin插件
 <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <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>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <distributionManagement>
        <repository>
            <id>ossrh</id>
            <name>Nexus Release Repository</name>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
        <snapshotRepository>
            <id>ossrh</id>
            <name>Sonatype Nexus Snapshots</name>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>
  • 配置本地maven setting.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <localRepository>D:/repo/m2</localRepository>

   <profiles>
    <profile>
      <id>ossrh</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gpg.executable>gpg</gpg.executable>   
        <gpg.passphrase>aaa</gpg.passphrase>  //本地gpg密鑰passphrase,生成方式參見上面圖例,如果密鑰生成時(shí)沒密碼,那就無所謂了
      </properties>
    </profile>
  </profiles>
    <servers>
       <server>
            <id>ossrh</id>
            <username>hdfasd</username>  //上面sonatype注冊的帳號及密碼
            <password>aaa</password>  //sonatype密碼
        </server>
        
    </servers>
</settings>
  • 現(xiàn)在就可以上傳jar包了,需要說明下:采用maven默認(rèn)插件上傳jar包時(shí),是默認(rèn)在一個(gè)臨時(shí)倉庫中,此時(shí)在maven中是找不到該依賴的,如果是官方的nexus-staging-maven-plugin插件是可以配置為直接上傳到倉庫中心的,臨時(shí)倉庫有個(gè)好處就是可以隨時(shí)修改,然后修改確認(rèn)好后,再發(fā)布到maven倉庫中,臨時(shí)倉庫通過https://s01.oss.sonatype.org/訪問,用上面注冊的sonatype帳號登錄,具體如下圖
2-2.png

2-1.png
2-3.png
  • 至此,上傳完成,等待30分鐘至4小時(shí),maven倉庫就同步完成了,就可以找到對應(yīng)的jar包了
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容