如何仅在maven-jarsigner-plugin中发布时配置TSA参数

时间:2013-01-04 21:03:31

标签: java maven pom.xml jarsigner

在我们的jar中添加时间戳会导致我们的maven构建比平常花费大约4倍。时间戳是发布版本所必需的,但我们不需要它来进行快照构建。我们如何将POM文件配置为仅在发布版本时添加TSA参数(即SNAPSHOT未出现在项目版本中)。

以下是我们的jarsigner插件的POM条目。请注意底部添加的参数。如果SNAPSHOT出现在项目版本中,我们希望不添加这些:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jarsigner-plugin</artifactId>
          <version>1.2</version>
          <executions>
            <execution>
              <id>sign webcontent jars</id>
              <phase>prepare-package</phase>
              <goals>
                <goal>sign</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <archiveDirectory>${project.build.directory}/projectname-webcontent/applets</archiveDirectory>
            <includes>
              <include>*.jar</include>
            </includes>
            <keystore>Keystore</keystore>
            <alias>alias</alias>
            <storepass>pass</storepass>
            <arguments>
              <argument>-tsa</argument>
              <argument>https://timestamp.geotrust.com/tsa</argument>
            </arguments>
          </configuration>
        </plugin>

1 个答案:

答案 0 :(得分:2)

假设您正在为您的版本使用maven发行版插件,您可以通过捎带它激活的发布配置文件来实现此目的。

如果您喜欢或不使用发布插件来发布您的版本,也可以使用自己的自定义配置文件执行此操作。

在你的pom中,你会包括:

<profiles>
    <profile>
        <id>release-profile</id>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jarsigner-plugin</artifactId>
            ...
            <!-- Put your configuration with the TSA here -->
        </plugin>
    </profile>
</profiles>

现在在jarsigner的构建/插件配置的正常部分中省略TSA参数。如果您出于某种原因碰巧希望TSA带有快照,您可以使用以下方法手动激活发布配置文件:

mvn -Prelease-profile install