You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven发布到Sonatype时GPG签名提示skipped无私钥如何解决?

问题背景

参考Maven中央仓库发布教程将项目发布到Sonatype仓库时,构件签名环节出现构建失败。
报错日志如下:

[INFO] --- maven-gpg-plugin:3.0.1:sign (sign-artifacts) @ exceptionless-client ---
gpg: skipped "0x9d0e3e1d": No secret key
gpg: signing failed: No secret key
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  42.750 s
[INFO] Finished at: 2021-08-03T10:52:18+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:3.0.1:sign (sign-artifacts) on project exceptionless-client: Exit code: 2 -> [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 --list-key命令可以看到对应密钥存在,可按以下步骤排查解决:

解决方案
  • 核对执行用户一致性:检查执行gpg --list-key的用户和执行Maven命令的用户是否一致。如果Maven用sudo权限执行,普通用户下的密钥对默认不会被sudo环境识别,可执行sudo gpg --list-key核对sudo环境下是否存在对应密钥。
  • 配置GPG终端环境变量:输入密钥密码需要终端交互的场景,缺失GPG_TTY变量会导致签名失败,执行如下命令配置后重试:
    export GPG_TTY=$(tty)
    
  • 调整密钥信任等级:如果密钥未设置为最终信任,也会触发签名失败,执行以下命令调整:
    gpg --edit-key 0x9d0e3e1d
    # 进入交互界面后输入 trust,选择等级5(最终信任),输入 save 保存退出
    
  • 修正maven-gpg-plugin配置:
    1. 如果系统默认安装的是gpg2,需指定gpg可执行文件路径,在项目pom.xml的maven-gpg-plugin配置中添加:
      <executable>gpg2</executable>
      
    2. 显式指定签名使用的密钥ID,在pom.properties或者settings.xml中添加配置:
      <gpg.keyname>0x9d0e3e1d</gpg.keyname>
      
  • 命令行临时指定参数测试:执行Maven命令时直接传入签名参数,验证是否可正常签名:
    mvn clean deploy -Dgpg.keyname=0x9d0e3e1d -Dgpg.passphrase=你的密钥密码
    

内容的提问来源于stack exchange,提问作者Prashant

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 11:42:03