全部学科
Python全栈
python
NodeJS全栈
nodejs
📅 2026-05-23 10 分钟 ✍️ juanwangdev

构件签名与安全验证

GPG 签名验证构件完整性。

GPG 配置

安装 GPG

Bash
# Linux
apt-get install gnupg

# Windows
下载 Gpg4win

生成密钥

Bash
gpg --gen-key

Maven 配置

XML
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-gpg-plugin</artifactId>
  <version>1.6</version>
  <executions>
    <execution>
      <phase>verify</phase>
      <goals>
        <goal>sign</goal>
      </goals>
    </execution>
  </executions>
</plugin>

settings.xml 配置

XML
<profile>
  <id>gpg</id>
  <properties>
    <gpg.executable>gpg</gpg.executable>
    <gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
  </properties>
</profile>

要点总结

  • gpg --gen-key 生成密钥
  • maven-gpg-plugin 签名构件
  • verify 阶段执行签名
  • GPG_PASSPHRASE 环境变量传入密码
想在手机上练习这篇文章的配套题目?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码
← 上一篇 快照与正式版发布策略
下一篇 → 仓库清理与存储优化
扫码体验小程序
加载中
想在手机上刷题学习?
使用微信卷王开发者小程序,打开首页顶部扫码功能识别二维码