使用gradle:jdk8镜像时GitLab CI中keytool报-cacerts非法选项错误
Fixing the keytool Error with gradle:jdk8 in GitLab CI
The error Illegal option: -cacerts pops up because the keytool command syntax differs between JDK 8 and JDK 11. In JDK 8, you can’t use -cacerts as a standalone option—you need to explicitly point to the cacerts keystore file using the -keystore parameter instead.
Here’s the corrected gitlab-ci.yml configuration that works with the gradle:jdk8 image:
image: gradle:jdk8 stages: - build - publish before_script: - wget -P /tmp http://www.some.com/SOME.crt - keytool -importcert -trustcacerts -file /tmp/SOME.crt -keystore $JAVA_HOME/jre/lib/security/cacerts -alias "Some" -storepass changeit -noprompt
What’s the change?
- We replaced
-cacertswith-keystore $JAVA_HOME/jre/lib/security/cacerts: In JDK 8, the cacerts file lives in thejre/lib/securitysubfolder of your JAVA_HOME directory. Using the$JAVA_HOMEenvironment variable makes this path dynamic and reliable across different JDK 8 setups. - The rest of the command remains identical—we’re still importing the certificate into the trusted CA store, just using the syntax that JDK 8’s
keytoolrecognizes.
This adjustment will fix the illegal option error and let your pipeline run smoothly with the gradle:jdk8 image.
内容的提问来源于stack exchange,提问作者Valeriy K.
相关产品推荐
相关产品推荐

