【问题标题】:Maven - Generating JARs GPG signaturesMaven - 生成 JARs GPG 签名
【发布时间】:2014-04-08 20:10:02
【问题描述】:

我是新来的 Maven 和上传东西到 Sonatype,所以错误可能很明显,但它对我隐藏得很好。我正在尝试上传工件。

为此,我运行以下命令

mvn clean assembly:single -s settings.xml assembly:single javadoc:jar source:jar gpg:sign -Dgpg.passphrase=myPassphrase install deploy

但是,这会导致 Nexus 无法验证 JAR 文件,因为上传中没有包含 asc 签名文件 - 这是真的,但我不明白为什么。此外,还有 .xml 文件以及 .zip、.tar.gz 和 .tar.bz2 文件的签名。我应该为 jars 生成 ascs 指定什么?

下面显示了我的 settings.xml 和 pom.xml 文件:

settings.xml:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>sonatype</id>
      <username>myUsername</username>
      <password>myPassword</password>
    </server>
  </servers>

</settings>

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.github.aaryn101</groupId>
  <artifactId>lol4j</artifactId>
  <version>2.0</version>
  <packaging>jar</packaging>

  <name>lol4j</name>
  <description>lol4j is a Java wrapper for the Riot Games LoL beta API.</description>
  <url>https://github.com/aaryn101/lol4j</url>

  <licenses>
    <license>
      <name>The MIT License (MIT)</name>
      <url>http://opensource.org/licenses/MIT</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <scm>
    <url>https://github.com/aaryn101/lol4j.git</url>
  </scm>

  <distributionManagement>
  <repository>
    <id>sonatype</id>
    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
  </repository>
  </distributionManagement>

<build>
  <plugins>
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <descriptor>dep.xml</descriptor>
        </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-javadoc-plugin</artifactId>
      <version>2.9.1</version>
      <executions>  
        <execution>
          <id>attach-javadocs</id>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <artifactId>maven-source-plugin</artifactId>
      <version>2.2.1</version>
      <executions>
        <execution>
          <id>attach-sources</id>
          <goals>
            <goal>jar</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
</project>

【问题讨论】:

    标签: java maven jar gnupg sonatype


    【解决方案1】:

    为了将 jars 上传到 maven 存储库,您需要使用必须在给定密钥服务器上提供的公钥对它们进行签名。请参阅此处detailed instructions,此blog post 也很有帮助。

    最重要的步骤是创建密钥并将其上传到密钥服务器(在上面的链接中有详细说明)。

    然后编辑 settings.xml 以使 PGP 密钥对 Maven 可用:

    <profiles>
          <profile>
              <id>gpg</id>
              <properties>
                  <gpg.passphrase>your passphrase</gpg.passphrase>
                  <gpg.keyname>your pgp key</gpg.keyname>
              </properties>
          </profile>
      </profiles>
    

    然后将其添加到 pom.xml 中以对 jars 进行签名:

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

    这是working pom.xml 的示例。

    【讨论】:

    • 好的,谢谢,有了这些信息,我已经设法创建了我认为的正确 pom,尽管有些奇怪 - 我在你的工作 pom.xml 示例中得到了一个“重复的存储库标签”。无论如何,现在,我在尝试部署时收到 401 未经授权的错误。我一直在阅读this FAQ about the 401 problem,但其中提到的所有内容对我来说似乎都很好。还有其他建议吗?
    猜你喜欢
    • 2013-02-01
    • 2010-11-05
    • 2016-08-19
    • 2016-04-16
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多