生产环境下签署Maven构件的最佳实践是什么?

4

当我和我的团队需要将新的 Maven 构件发布到中央仓库时,我们使用的过程如下:

mvn release:clean
mvn release:prepare
mvn release:perform

一切都运行良好。

当然,pom.xml 包含了对 Maven gpg 插件的引用,以封装 jar 包:

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

如果执行mvn release:perform失败:

但在开发过程中,我们中的一些人没有/无法安装gpg.exe程序或签名密钥(只有主要开发者拥有正确的密钥来封闭最终的JAR包)。

因此,如果我们在本地执行mvn clean install或其他类型的命令,该过程将失败,并且在开发过程中无法将本地修改后的JAR包放入.m2文件夹中。

在执行命令mvn release:perform时如何最好地进行软件包签名?

1个回答

1
发布和签署程序包的问题已经解决。你可以使用一个配置文件来激活签署插件。更多详细信息和背后的故事请点击这里 https://blog.sonatype.com/2010/01/how-to-generate-pgp-signatures-with-maven/
<profiles>
  <profile>
      <id>release-sign-artifacts</id>
      <activation>
        <property>
          <name>performRelease</name>
          <value>true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
  </profile>
</profiles>

已经尝试了该网站上的解决方案,但不起作用。首先,它在语法上是不正确的,因为它说:“[警告]构建有效设置时遇到了一些问题[警告]未识别的标记:'build'(位置:START_TAG seen ...</activation>\r\n\t\t\t<build>。” 即使我在命令行中使用-DperformRelease=true也不起作用。 - Marco Vasapollo
1
@MarcoVasapollo 页面上描述的profiles部分是正确的。但它没有解释如何激活配置文件。应该使用deploy插件的useReleaseProfilereleaseProfiles配置属性进行激活,正如文档中所述。 - Pawel Veselov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接