我正在使用 keytool-maven-plugin将 alias.cer 文件导入 java cacerts 存储,它工作正常。第二次构建项目时出现问题;收到错误,因为 alias.cer 文件已添加到存储中。我看不到任何参数来解决插件中的问题。有“skip”和“skipIfExist”参数。这些参数不是为了这个目的; skip 禁用插件,如果商店已经存在,skipIfExist 跳过。
我怎么能解决这个问题?或者你知道这个目标的替代插件吗?
最佳答案
我意识到这个插件是通过 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
关于java - 如果使用 keytool-maven-plugin 已经存在证书,如何跳过 importCertificate 目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63774504/