Java上传本地jar包到maven中央仓库的坑逼经历

上传jar的流程参考下面几个博客:
https://blog.csdn.net/qq_38225558/article/details/94381467
https://www.jianshu.com/p/923913d904fb

但是就这样还是出了一堆错,这里记录一下。

一、setting.xml配置中添加节点信息

这里的Sonatype账号是账号,不是邮箱,如果填错了mvn clean deploy时jar上传中央仓库的会很慢,或者直接报401的错误。

<servers>
  <!-- 上传jar包到maven中央仓库配置start -->
  <server>
      <id>ossrh</id>
      <username>Sonatype账号</username>
      <password>Sonatype密码</password>
  </server>
  <!-- 上传jar包到maven中央仓库配置end -->
</servers>

二、setting.xml配置中添加gpg信息

mvn clean deploy时报Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (default) on project xxxx: Exit code: 1 -> [Help 1] 错误

'gpg.exe' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.359 s
[INFO] Finished at: 2020-04-10T11:15:19+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (default) on project trace-spring-boot-starter: Exit code: 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

gpg.exe已经添加环境变量了,命令行可以运行,但是部署的时候找不到。
直接在setting.xml中配置gpg的绝对路径位置,就不会找不打了。

<profile>
	<id>ossrh</id>
	<activation>
		<activeByDefault>true</activeByDefault>
	</activation>
	
	<properties>
		<gpg.executable>C:\Users\Administrator\SoftWare\GnuPG\bin\gpg</gpg.executable>
		<gpg.passphrase>你的gpg的Passphrase</gpg.passphrase>
	</properties>
</profile>

再次运行mvn clean deploy时,弹出如下窗口说明正确。
gpg

三、nexus repository close failed

对于mvn clean deploy时报Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (default) on project xxxx: Exit code: 1 -> [Help 1] 错误。
网上有个点赞很多的解决方案是配置<pluginManagement></pluginManagement>到maven插件的位置,但是这个方法只是不执行source、javadoc、gpg插件,能成功将jar deploy到Nexus Repository,但是在Nexus Repository进行close时会出现如下错误。

Event: Failed: Javadoc Validation
typeId	javadoc-staging
Event: Failed: Signature Validation
typeId	signature-staging
Event: Failed: Sources Validation
typeId	sources-staging
Event: Close failed

Event: Failed: Javadoc Validation
找不到javadoc、source等错误。

mvn clean deploy时不能跳过source、javadoc、gpg插件。在个人的maven repository中要看到如下文件后缀的文件
在这里插入图片描述

四、Event: Failed: Signature Validation

.jar、.jar.asc、pom、pom.asc、javadoc.jar、javadoc.jar.asc、source.jar、source.jar.asc都正确打包后。在nexus repository进行close时出现如下错误。
在这里插入图片描述

Event: Failed: Signature Validation
Friday, April 10, 2020 11:55:19 (GMT+0800)
typeId	signature-staging
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://keyserver.ubuntu.com:11371/">http://keyserver.ubuntu.com:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://keys.openpgp.org:11371/">http://keys.openpgp.org:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://pool.sks-keyservers.net:11371/">http://pool.sks-keyservers.net:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://keyserver.ubuntu.com:11371/">http://keyserver.ubuntu.com:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://keys.openpgp.org:11371/">http://keys.openpgp.org:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://pool.sks-keyservers.net:11371/">http://pool.sks-keyservers.net:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://keyserver.ubuntu.com:11371/">http://keyserver.ubuntu.com:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://keys.openpgp.org:11371/">http://keys.openpgp.org:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://pool.sks-keyservers.net:11371/">http://pool.sks-keyservers.net:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://keyserver.ubuntu.com:11371/">http://keyserver.ubuntu.com:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://keys.openpgp.org:11371/">http://keys.openpgp.org:11371/</a>. Upload your public key and try the operation again.
failureMessage	No public key: Key with id: (7c95ee78d7c7bc7) was not able to be located on <a href="http://pool.sks-keyservers.net:11371/">http://pool.sks-keyservers.net:11371/</a>. Upload your public key and try the operation again.

需要将公钥发布到 PGP 密钥服务器,两个密钥服务器都要发布,我只发布了一个,导致了错误。

gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 公钥ID
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公钥ID

查询公钥是否发布成功

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 公钥ID
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 公钥ID

公钥通过如下命令查询

gpg --list-keys

五、上传maven中央仓库成功

最终close成功😭
在这里插入图片描述
发布release版本😭
在这里插入图片描述
等待两个小时后,在maven中央仓库搜到了自己的写的jar😃

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值