Sometimes I need to install a cacert into my jdk s...
# community-support
c
Sometimes I need to install a cacert into my jdk so that gradle can pull down dependencies for my project. If I try to sync gradle, and it fails... and then i install the cacert... i can't sync gradle again and get a success. instead... I need to delete the global
.gradle
folder on my mac. then sync again. and everything works. Anyone know why that is? deleting
.gradle
is a heavy operation and id love to only delete a specific file or something inside of
.gradle
if anyone knows the true culprit.
e
p
Also, if you/your IT department installed the caceet into your system store, it is way easier to just use the system store. (Looking at you, zScaler…)
v
Instead of deleting your whole Gradle User Home, is it not sufficient to use
--refresh-dependencies
or to use the according IDE button?
e
my old post is hidden on slack desktop but visible on slack mobile, good job slack
c
Instead of deleting your whole Gradle User Home, is it not sufficient to use
--refresh-dependencies
or to use the according IDE button?
correct. ive tried those two things. no dice.
surely something like https://gradle-community.slack.com/archives/CAHSN3LDN/p1723196089290129?thread_ts=1723190399.276349&cid=CAHSN3LDN would be easier than modifying your JDKs?
interesting. i thought modifying my JDKs to install the ca-cert WAS the only way. theres like a document that over 1k people at my job use to run these commands manually to install the cert into your jdk. lol. id love if there was another option. ill try to checkout your script.
Also, if you/your IT department installed the caceet into your system store, it is way easier to just use the system store. (Looking at you, zScaler…)
we all use macs. are you saying that if i install the cacert into my mac keystore I won't have to put it in my jdk. hm. let me try that.
e
you can read the script. it makes a local copy of the keystore with an added key, then tells the current JVM to use it instead. you could of course do it in a variety of other ways, but there's never a need to modify the JDK itself.
c
gotcha. it seems like after macOS updates the jdk loses the installed cert. which is why im running into this issue now.
noob question though. i looked at your script. where do i put that? i guess i would commit it to the repo, but I also need to plug that into my build somewhere, right?
p
For Gradle: # local zScaler proxy host and port systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=9000 # to support zScaler TLS inspection, use the Windows cert storage with the zScaler cert systemProp.javax.net.ssl.trustStoreType=Windows-ROOT # macOS systemProp.javax.net.ssl.trustStoreType=KeychainStore
c
@Philip W since im on mac os... i would install the cert into my mac keystore. and then just add
<http://systemProp.javax.net|systemProp.javax.net>.ssl.trustStoreType=KeychainStore
to my gradle.properties? Am I understanding that correctly?
and yes, we do use zscaler 😭
p
Des
c
cool. do i need to add those zscaler lines as well? im going to give this a try this weekend. would be awesome to not have to hit this issue every time macOS updates lol
e
my script goes in
~/.gradle/init.d/certs.init.gradle.kts
. there's no way to put it in the local build and have Gradle automatically apply it https://github.com/gradle/gradle/issues/17826
but you could just as well have a standard keystore in a static file somewhere and add it to gradle.properties jvmopts
c
oh! it goes into global .gradle dir. even better!
oh. i really like that solution. so i dont have to do it for all of our repos. i also like phillips solution. let me see if any of these give me issues this weekend when i debug. would love to solve this problem once and for all. installing into every jdk is SOOO annoying. so if i could do this. itd be a GAME CHANGER
i wonder if this will fix gradle-profiler from not working. because at my company. for whatever reason... gradle-profiler will just not work even though the jdk has the ca certs installed.
im so happy i ask seemingly dumb questions sometimes
v
There are no dumb questions, just dumb answers 🙂
We all were at the point where we did not know the answer and just learned it in the meantime ... or not 😄
Btw. the
<http://systemProp.javax.net|systemProp.javax.net>.ssl.trustStoreType
you can also do in your
GRADLE_USER_HOME
instead of in the project. Because if you do it in the project, then you actually switch that for everyone whether they have the cert in their OS store or not. Unless of course all consumers of those builds have that in the OS store automatically and no other people need to execute those builds.
c
Oh true. I forgot i could just set the props there. ❤️
👌 1
p
BTW zScaler installs its own tls certificate automatically into the system keystore, so all you need are the three properties.
c
oooh interesting. okay. i'll add the three props. 🤞
Updating here in realtime... but it seems like all I needed was
<http://systemProp.javax.net|systemProp.javax.net>.ssl.trustStoreType=KeychainStore
and everything is working. no proxy.* flags needed.
awesome. so now if gradle-profiler doesn't work i can just do `gradle-profiler --gradle-user-home ~/.gradle" and it'll use the systemProp set there. WOOO. I AM SO HAPPY
and thanks @Vampire on the tip for --refresh-dependencies as that allowed me to quickly test without having to nuke .gradle folder
v
Copy code
JAVA_TOOL_OPTIONS=-Djavax.net.ssl.trustStoreType=KeychainStore gradle-profiler
?
c
interesting. id just set that as an env variable? edit: tried adding it as an env var and it failed when going that route.
v
Yes, that one-liner sets it as the variable for that call, but you can also set it as regular env variable. It's strange that it does not work. That env variable is read by the JVM itself upon start and can be used to give options to any JVM started, no matter how. Did it output that it found the variable and just had no effect or did it not even output that?
c
I ran
Copy code
JAVA_TOOL_OPTIONS=-Djavax.net.ssl.trustStoreType=KeychainStore gradle-profiler --benchmark --scenario-file scenarios.txt
and i get the ssl issue when running but if I do
Copy code
gradle-profiler --gradle-user-home ~/.gradle --benchmark --scenario-file scenarios.txt
then it works.
v
But did you get the
Picked up JAVA_TOOL_OPTIONS: -<http://Djavax.net|Djavax.net>.ssl.trustStoreType=KeychainStore
message? And especially not from the
gradle-profiler
JVM but from the Gradle daemon JVM where you need it.
c
"Picked up" I did not
if I ran
export JAVA_TOOL_OPTIONS...
then it did work! so I guess something about
JAVA_TOOL_OPTIONS=-<http://Djavax.net|Djavax.net>.ssl.trustStoreType=KeychainStore gradle-profiler --benchmark --scenario-file scenarios.txt
that it doesn't like (at least on macos)
so now I wonder if I'm better off just adding
export JAVA_TOOL_OPTIONS=-<http://Djavax.net|Djavax.net>.ssl.trustStoreType=KeychainStore
and i dont need to touch gradle.properties
ah. thanks to chatgpt. found my issue. I was actually running ``JAVA_TOOLS_OPTIONS=-Djavax.net.ssl.trustStoreType=KeychainStore gradle-profiler --benchmark --scenario-file scenarios.txt`` with an extra S on TOOL. all worked now just like you said. thanks @Vampire Now I'm going to try to compare and contrast what should be the recommendation for my team. Either A: add an env variable for JAVA_TOOL_OPTIONS B: add a global gradle property
v
Depends on whether you want it for each and every started JVM on the computer and don't mind the "picked up" line which you cannot disable, or only want it for Gradle.
c
got it. for now those are two insanely great solution. FWIW, installing the cert into a jdk still seems to be sometimes needed for zscalar. the example I have is that my SO works at a different company than me, but still has zscalar. i told them about this "trick", and it would not work. then i installaed the cert into the jdk and it worked. we spent 5 hours yesterday trying to get it to work with the JAVA_TOOL_OPTIONS technique and the gradle.properties technique but no luck. its almost like on their laptop the macOS keystore doesn't get picked up correctly. We tried installing the cert into mac keystore, and a bunch of chatgpt'ing, but nothing. darn. was hoping that my solution would work for them too.
spent another 2 hours just now on top of the 5 yesterday. my SO's machine just will not work unless you install teh cert into the jdk. FWIW, we also referenced https://help.zscaler.com/zia/adding-custom-certificate-application-specific-trust-store which says 0 about KeychanStore technique. Seems like they recommend installing the certificate directly. im going to try to write a utility that tries to find all jdks on the machine and installs the cert into each one. that still seems like the best long term approach /shruggie