maven发布jar包至nexus新版仓库(PGP密钥模式)

准备:

1-2.png

根据提示生成即可。


1-1.png
1-3.png
1-4.png
1-5.png
  • 注册sonatype帐号,上传jar包认证帐号就是此帐号,注册地址:https://issues.sonatype.org/
  • 开通sonatype权限,按下面图片中的步骤即可:
    1.jpg
2.png
3.png
4.png
  • 配置pom.xml,采用的是apache maven默认插件打包上传,非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,生成方式参见上面图例,如果密钥生成时没密码,那就无所谓了
      </properties>
    </profile>
  </profiles>
    <servers>
       <server>
            <id>ossrh</id>
            <username>hdfasd</username>  //上面sonatype注册的帐号及密码
            <password>aaa</password>  //sonatype密码
        </server>
        
    </servers>
</settings>
  • 现在就可以上传jar包了,需要说明下:采用maven默认插件上传jar包时,是默认在一个临时仓库中,此时在maven中是找不到该依赖的,如果是官方的nexus-staging-maven-plugin插件是可以配置为直接上传到仓库中心的,临时仓库有个好处就是可以随时修改,然后修改确认好后,再发布到maven仓库中,临时仓库通过https://s01.oss.sonatype.org/访问,用上面注册的sonatype帐号登录,具体如下图
2-2.png

2-1.png
2-3.png
  • 至此,上传完成,等待30分钟至4小时,maven仓库就同步完成了,就可以找到对应的jar包了
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容