我有几个项目,我想用gpg密钥对生成的工件进行签名。在过去,我使用gpg1.x(即旧的),在这个设置中,我在~/.m2/settings-security.xml中对密码进行了加密(但可以使用)。
我不喜欢这样(但在我写这篇文章的时候,它是我设法开始运行的设置)。
我最近开始考虑是否可以在不存储密码的情况下让它全部运行。因此,现在在~/.m2/settings.xml中,我有类似这样的东西(此配置文件处于活动状态):
<profile>
<id>signingkey</id>
<properties>
<gpg.executable>gpg2</gpg.executable>
<gpg.keyname>ABCDEF01</gpg.keyname>
</properties>
</profile>在pom.xml中,我有一个带有以下基本配置的maven-gpg-plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>现在,当我在Ubuntu16.04系统上执行此操作时,gpg-agent (gpg2的一部分)和gnome-keyring-daemon会在第一次使用后记住密码。
因此,在这个系统上,我通常处于已经运行gpg-agent的情况下,因此,当我在项目中使用mvn clean verify对工件进行签名时,不会询问任何问题,因为密码在gpg-agent中可用。
到目前一切尚好。
为了确保我拥有完美干净的软件构建(对于一些项目,也为了确保所有工具都正确安装),我经常从单独的docker环境构建/部署软件。
在这样一个“非常干净”的docker环境中,启动时没有gpg-agent,我发现简单地运行mvn clean verify会生成一个没有签名的构建,因为我得到了
You need a passphrase to unlock the secret key for
user: "Niels Basjes (Software Signing Key) <signed@basjes.nl>"
...
gpg: cancelled by user据我所知,因为我应该输入密码,但没有提供提示。
此时,我只找到了一种解决方法,那就是在构建软件之前执行类似gpg2 --sign pom.xml的操作,因为这会启动gpg-agent并显示一个对话框来输入密码。
我想要的是更改我的设置,这样我就可以简单地执行mvn verify,第一次登录尝试将为我弹出密码对话框,并将密码缓存到gpg-agent中。
本质上,我的问题是如何做到这一点;或者更好的是:设置它的正确方法是什么?
发布于 2018-08-13 23:37:06
您可以使用以下配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<executable>gpg2</executable>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
<passphrase>${gpg.passphrase}</passphrase>
</configuration>
</execution>
</executions>
</plugin>将您的gpg密码放入带有配置文件的settings.xml文件中,并使用该配置文件进行构建。属性名称是固定的,不能更改。也可以使用属性gpg.executable以这种方式设置可执行文件
<properties>
<gpg.passphrase>MySpecialPassword</gpg.passphrase>
</properties>https://stackoverflow.com/questions/49477132
复制相似问题