Maven jarsigner插件配置不起作用

时间:2018-02-09 10:09:26

标签: java maven jarsigner jar-signing maven-jarsigner-plugin

我正在尝试使用以下pom.xml配置来签署一个jar文件。

 if let uploadData = UIImagePNGRepresentation(self.myImageView.image!) {
    storageRef.put(uploadData, metadata: nil) { (metadata, error) in
        if error != nil {
            print("error")

        } else {

            // your uploaded photo url.
        }
   }

keystore.jks与pom.xml位于同一文件夹中。 运行" mvn clean package"后,ROOT.jar可用于目标。 allias是正确的,所使用的密码也是正确的。

当我用" jarsigner -verify path \ to \ target \ ROOT.jar"

验证jar时

我得到" jar是未签名的。" 有没有人知道我的pom有什么问题?

编辑:Apache Maven 3.5.2 Java版本:1.8.0_161 Full Pom:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jarsigner-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <id>sign</id>
                        <phase>package</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <archive>${basedir}/target/ROOT.jar</archive>
                    <keystore>${basedir}/keystore.jks</keystore>
                    <alias>my_certificate_alias</alias>
                    <storepass>123456</storepass>
                    <keypass>123456</keypass>
                </configuration>
            </plugin>

1 个答案:

答案 0 :(得分:1)

我假设完整的POM是正确的(它与您的初始代码段不同)。

jarsigner声明移到<pluginManagement>部分之外:

<build>
  <pluginManagement>
     <plugins>
       ... <!-- Move the jarsigner from here -->
     </plugins>
  </pluginManagement>
  <plugins>
    <!-- To here: -->
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jarsigner-plugin</artifactId>
      <version>1.4</version>
      <executions>
        <execution>
          <id>signer</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>sign</goal>
          </goals>
         </execution>
      </executions>
      <configuration>
        <archive>${basedir}/target/ROOT.jar</archive>
        <keystore>${basedir}/keystore.jks</keystore>
        <alias>my_certificate_alias</alias>
        <storepass>123456</storepass>
        <keypass>123456</keypass>
      </configuration>
    </plugin>
  </plugins>
</build>

接下来,将<phase>prepare-package更改为package

  <execution>
    <id>signer</id>
    <phase>package</phase>  <!-- The JAR is not created in prepare-package -->
    <goals>
      <goal>sign</goal>
    </goals>
  </execution>