Gradle wrapper times out when using a proxy

1.9k Views Asked by At

This question is specifically about the Gradle wrapper and not a full Gradle installation.

My company forces me to use a proxy to access many urls, and all it usually takes to fix timeout problems is to configure whatever is trying to access said urls to use the proxy, after which I get a certificate verification error and I have to also add the sites' SSL certificates to Java's keystore (take this answer as an example for how to do the latter).

With the Gradle wrapper (version 7.4.1+), though, I'm still getting a timeout.
I searched, and I found many people appearing to have this problem. Most of them though, simply had to configure the proxy in the gradle.properties file (on Windows it's by default in %userprofile%\.gradle):

systemProp.http.proxyHost=the proxy host
systemProp.http.proxyPort=the port
systemProp.http.proxyUser=username (if authentication is needed)
systemProp.http.proxyPassword=password (if authentication is needed)
systemProp.https.proxyHost=the proxy host
systemProp.https.proxyPort=the port
systemProp.https.proxyUser=username (if authentication is needed)
systemProp.https.proxyPassword=password (if authentication is needed)

Or, they had to remove a wrong proxy configuration from the file.
A few of them solved the problem by increasing Gradle's timeouts with these properties:

systemProp.org.gradle.internal.http.connectionTimeout=300000
systemProp.org.gradle.internal.http.socketTimeout=300000

These solutions aren't working for me. Why?

1

There are 1 best solutions below

1
On BEST ANSWER

I found the cause to be an hardcoded connection timeout value in the sources of the gradle-wrapper. See this issue in their Github; it seems they're gonna fix it for version 7.6.

The org.gradle.internal.http.connectionTimeout and org.gradle.internal.http.socketTimeout system properties mentioned in the question are only taken into account by Gradle "proper", not by the wrapper.

So, setting longer timeout wait times in the gradle.properties file doesn't work. How to solve the issue without manually downloading stuff from the Gradle site?
One way would be to recompile the wrapper from the sources after changing the timeouts. Another easier solution though is to edit the compiled jar. You can use something like Recaf for that.

change the pesky timeouts

Then you replace the gradle-wrapper.jar you were using and try again.

Once the wrapper manages to download the "dist" the first time, you might not run into this problem anymore even with the original jar.

If you do get a timeout again after that first time, then this is what you have to do to make sure that the modified gradle-wrapper.jar is used instead of the original, for example by IDEs when creating new projects:

  • go to %userprofile%\.gradle\wrapper\dists\gradle-<version>-bin\<folder with a random-looking name>\gradle-<version>\lib
    For example in my case it was:
    C:\Users\username\.gradle\wrapper\dists\gradle-7.4.2-bin\48ivgl02cpt2ed3fh9dbalvx8\gradle-7.4.2\lib

  • open the gradle-wrapper-<version>.jar file

  • replace the gradle-wrapper.jar that's inside it with the modified one.

Yes, it's a jar containing another similarly-named jar. Don't replace the outer one with your modified jar.

enter image description here