Skip to content

Gradle(w) and Proxy Authentication

June 18th, 2015 - Software(1 min)

The recent updates in Android Studio eliminate the possibility of passing JVM arguments to gradle. That’s quite unfortunate because I quite liked my solution and now I was getting a (not) nice Connection refused message… So I had to find a different solution.

Environment Variable

As always, everything related to Java can be configured via an environment variable. if you set GRADLE_OPTS, it’ll get passed to gradlew as JVM arguments. My GRADLE_OPTS looks like this now: -Dhttp.proxyPort=pppp \ -Dhttps.proxyPort=pppp \
-Dhttp.proxyUser=_username_ -Dhttp.proxyPassword=_password_

You should need to set up the https variants because downloads are made via https, not http. The user name and password are the same as for http. if youre proxy is not authenticated, then good for you. I’m not that lucky :)

The advantage of this approach is that gradlew can make use of it.

Gradle Configuration

The same as above can be done in the file. This will make the settings available to gradle commands. My file looks like this now:

# Speedup

# Speedup and proxy settings
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -Dhttp.proxyPort=pppp \ -Dhttps.proxyPort=pppp \
-Dhttp.proxyUser=_username_ -Dhttp.proxyPassword=_password_

For some reason it would not work with gradlew, but I haven’t lingered too much on it. If you find this solution works with gradlew without the environment variable, let me know!


Share on

A little experiment: