I currently am running some REST calls behind a proxy, so I need to follow some strict processes in order for the calls to go through.
Previously I was building in Eclipse for a POC, but now that I know it works, I am trying to transfer it over to IntelliJ (Personal favorite IDEA) along with Gradle for the build automation.
I got the project to compile, export all the dependencies, etc... but when I run it IN IntelliJ I get a "Cert not found error". On a side note however, if I execute the compiled Jar file (from gradle) using "java-jar MyJar.jar", it runs perfectly and doesn't throw the cert error. The kicker here is, if I execute the Jar using JUST the gradle task outside of IntelliJ it works, but if I try to execute the task right after the build in IntelliJ it fails.
Works:
Doesn't work: - Executing the build task within IntelliJ and calling "runMain" at the end of the build task
My current theory, is that running it via java -jar and gradle runMain, causes the JVM to use the default cacerts "/jre_xxx/libs/security/cacerts" (where I already added the certificate) but when I execute the Jar within IntelliJ with Gradle, it uses a different location. I've also added the cert to "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.5\jre64\lib\security\cacerts" as well but I still recieved this eror while running it in IntelliJ.
task(runMain, dependsOn: 'classes', type: JavaExec) {
main = 'com.xxx.xx.x.Utopia'
classpath = sourceSets.main.runtimeClasspath
args=[
"-Djavax.net.ssl.trustStore=C:\\ProgramFiles\\Java\\jre1.8.0_121\\lib\\security\\cacerts"
]
}
Running this VIA CLI seems to work but never with the Gradle build task within IntelliJ.
Any help would be greatly appreciated.
EDIT: The error that I get ONLY while running it within IntelliJ (PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target)
1\system\tasks\cacerts (both VIA IntelliJ and java keytool), as well as C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.
When you make any dependency changes in your gradle build file, you might receive errors while building your project from within the IDE – as a result of IntelliJ not resolving the dependency changes. To resolve this issue, navigate to the Gradle Tool window via View -> Tool Windows -> Gradle
IntelliJ IDEA provides its own storage for trusted certificates. Use this page to manage this storage. Select this option if you want non-trusted certificates (that is the certificates that are not added to the list) to be accepted automatically, without sending a request to the server.
Add certificate manually to your jdk cert strore. download the certificate from browser. Find your jdk installation directory. You can try changing the path for the Gradle wrapper going to Eclipse > Preferences > Gradle. Choose Local Installation directory instead of Gradle Wrapper.
Import some certifications into Android Studio JDK cacerts from Android Studio’s cacerts. I used the following import command. $ keytool -importkeystore -v -srckeystore {src cacerts} -destkeystore {dest cacerts} 2. Add modified cacert path to gradle.properties-
After contacting JetBrains support with my issue, I was made aware of the problem. Logically I was under the assumption that the JRE would execute the JAR file, this is ONLY the case when running java -jar my.jar or executing Gradle from CLI. The way IntelliJ works is that it solely uses the JDK, so I had to modify the small JRE that was within the JDK. Once I did that and added it to the CACERTS found within my jdk.xxx/jre/lib/security/cacerts, I was able to resolve this issue.
https://youtrack.jetbrains.com/issue/IDEA-195428
In case anyone comes across this issue as well. I had added my certs to the JDK store and ensured IntelliJ was using the JDK however it would still fail when trying to download JARs. Turned out I had to kill the gradle deamon running in the background as it was persisting between IntelliJ restarts. I'm on windows so ps java | kill
worked in Powershell. pkill java
will work in Linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With