Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 373
ytWho Avatar asked Nov 06 '22 05:11

ytWho


1 Answers

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

like image 130
ytWho Avatar answered Nov 12 '22 15:11

ytWho