Gradle(w) and Proxy Authentication
1 min read

Gradle(w) and Proxy Authentication

Gradle(w) and Proxy Authentication

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:

GRADLE_OPTS=-Dhttp.proxyHost=xxx.xxx.xxx.xxx -Dhttp.proxyPort=pppp \
-Dhttps.proxyHost=xxx.xxx.xxx.xxx -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 gradle.properties file. This will make the settings available to gradle commands. My gradle.properties file looks like this now:

# Speedup
#
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureondemand=true

# Speedup and proxy settings
#
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -Dhttp.proxyHost=xxx.xxx.xxx.xxx -Dhttp.proxyPort=pppp \
-Dhttps.proxyHost=xxx.xxx.xxx.xxx -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!

HTH,