How to skip the importCertificate goal if certificate is already exist by using keytool-maven-plugin?

huangapple go评论74阅读模式
英文:

How to skip the importCertificate goal if certificate is already exist by using keytool-maven-plugin?

问题

我正在使用keytool-maven-plugin将alias.cer文件导入到Java cacerts存储中,这能正常运行。问题出现在第二次构建项目时;由于alias.cer文件已经添加到存储中,所以出现错误。我没有看到任何可以解决插件中这个问题的参数。有两个参数是'skip'和'skipIfExist'。这些参数并不是为了这个目的;skip会禁用插件,skipIfExist会在存储已存在时跳过。

我应该如何解决这个问题?或者您是否知道其他可实现此目标的插件?

英文:

I'm using keytool-maven-plugin to import alias.cer file into java cacerts store, it works fine. The problem occurs when building the project second time; getting an error because alias.cer file is already added to store. I couldn't see any parameter to fix the problem in plugin. There are 'skip' and 'skipIfExist' parameters. These parameters are not for this purpose; skip disables the plugin, skipIfExist skips if the store already exist.

How could I solve the problem? or do you know alternative plugin for this goal?

答案1

得分: 1

我意识到这个插件是在Java的keytool基础上开发的。在keytool中没有针对“如果证书已存在则跳过”的目的的任何参数。因此,我通过在构建项目时添加一个自定义参数来处理这个问题,即使用“skip”参数。

<properties>
     <cert.skip>true</cert.skip>
</properties>

<plugin>
    <!-- https://mvnrepository.com/artifact/org.codehaus.mojo/keytool-maven-plugin -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>keytool-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <goals>
                <goal>importCertificate</goal>
            </goals>
            <phase>generate-sources</phase>
        </execution>
    </executions>
    <configuration>
        <skip>${cert.skip}</skip>
        <keystore>${JAVA_HOME}/lib/security/cacerts</keystore>
        <storepass>changeit</storepass>
        <alias>alias</alias>
        <file>${basedir}/src/main/resources/alias.cer</file>
        <noprompt>true</noprompt>
    </configuration>
</plugin>

用法: mvn clean install -Dcert.skip=false

英文:

I realized that this plugin developed over the java keytool. There isn't any parameter in keytool for the 'skip if certificate is already exist' purpose. Therefore, I've used 'skip' parameter to handle this problem by adding a custom parameter to use while building the project.

<properties>
     <cert.skip>true</cert.skip>
</properties>

<plugin>
    <!-- https://mvnrepository.com/artifact/org.codehaus.mojo/keytool-maven-plugin -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>keytool-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <goals>
                <goal>importCertificate</goal>
            </goals>
            <phase>generate-sources</phase>
        </execution>
    </executions>
    <configuration>
        <skip>${cert.skip}</skip>
        <keystore>${JAVA_HOME}/lib/security/cacerts</keystore>
        <storepass>changeit</storepass>
        <alias>alias</alias>
        <file>${basedir}/src/main/resources/alias.cer</file>
        <noprompt>true</noprompt>
    </configuration>
</plugin>

Usage: mvn clean install -Dcert.skip=false

huangapple
  • 本文由 发表于 2020年9月7日 17:03:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/63774504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定