向maven中央仓库发布jar包或pom

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/MaxWoods/article/details/86552456

1.登录https://issues.sonatype.org/secure/Dashboard.jspa,当然前提是你要注册一个账号

2.如果是初次发布,你需要提交一个工单,注册你的groupId,注意同一个groupId的工单只用提交一次,具体步骤如下:

点击上方的create按钮,弹出"create Issue"对话框:

project选择:Community Support - Open Source Project Repository Hosting (OSSRH)

其它标有红色“*”的都根据实际情况填上:

注意group id的选择,如果你没有groud id对应的域名所有权,可参考:

http://central.sonatype.org/pages/choosing-your-coordinates.html

因为笔者拥用域名maxwoods.net,按工单处理的回复如下,意思就是要验证你的域名所有权:

Do you own the domain maxwoods.net? If so, please verify ownership via one of the following methods:

  • Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-45676 (Fastest)
  • Setup a redirect to your Github page (if it does not already exist)
  • Send an email to [email protected] referencing this issue from a maxwoods.net email address

If you do not own this domain, please read:
http://central.sonatype.org/pages/choosing-your-coordinates.html
You may also choose a groupId that reflects your project hosting, in this case, something like io.github.max-woods or com.github.max-woods

扫描二维码关注公众号,回复: 5053449 查看本文章

工单创建,等待处理,正常情况几分钟后就会处理,得到下面回复:

net.maxwoods has been prepared, now user(s) maxwoods can:

please comment on this ticket when you promoted your first release, thanks

3.发布到中央仓库的内容需要签名,所以要生成签名密钥:

首先到https://www.gpg4win.org/下载客户端,这里以windows为例,下载Gpg4win,安装成功后,在命令行执行:

gpg --gen-key

来生成密钥,需要输入名字和邮箱,并弹出一个对话框来输入密钥的保护密码,一定要记住,后面会用到:

查看生成的密钥,得到类似如下的输出,敏感部分打了掩码,pub就是生成的公钥,下面会用到:

> gpg --list-keys
C:/Users/chually/AppData/Roaming/gnupg/pubring.kbx
--------------------------------------------------
pub   rsa2048 2019-01-19 [SC] [expires: 2021-01-18]
      DBA0B31A211FED********9888DFF74CDCF7B287
uid           [ultimate] Max Woods <****@****.***>
sub   rsa2048 2019-01-19 [E] [expires: 2021-01-18]

上传公钥至: http://keys.gnupg.net:11371/

gpg --keyserver http://keys.gnupg.net:11371/ --send-keys DBA0B31A211FED********9888DFF74CDCF7B287

4.正确配置你的maven发布账号,打开maven的settings.xml,在servers中加入(请自行替换用户名密码):

    <server>
      <id>sonatype-nexus-staging</id>
      <username>maxwoods</username>
      <password>**********</password>
    </server>
	<server>
      <id>gpg.passphrase</id>
      <passphrase>**********</passphrase>
    </server>

5.正确配置你的pom文件:

继承下面的pom,可以让你减少部分配置:

    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>7</version>
    </parent>

repositories加入:

        <repository>
            <id>sonatype-nexus</id>
            <url>https://oss.sonatype.org/content/groups/staging</url>
        </repository>

配置发布服务器,注意id与maven的settings.xml中server的id是一致的:

    <distributionManagement>
        <repository>
            <id>sonatype-nexus-staging</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
        <snapshotRepository>
            <id>sonatype-nexus-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

到目前为止,你已经可以使用mvn deploy将snapshot和release包发布到sonatype的nexus中,但还不能被检索到。

加入gpg签名插件:

 <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>

用下面命令向中心服务器发布release版,中途会要你输入密钥保护密码:

mvn clean deploy -P sonatype-oss-release

登录https://oss.sonatype.org/#stagingRepositories,查看你发布的内容:

先执行close操作,再进行release操作。

猜你喜欢

转载自blog.csdn.net/MaxWoods/article/details/86552456
今日推荐