Accessing the web through a proxy

Configuring a proxy (for downloading dependencies, for example) is done via standard JVM system properties.

These properties can be set directly in the build script. For example, setting the HTTP proxy host would be done with System.setProperty('http.proxyHost', 'www.somehost.org').

Alternatively, the properties can be specified in gradle.properties.

Example 1: Configuring an HTTP proxy using gradle.properties:

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

There are separate settings for HTTPS.

Example 2: Configuring an HTTPS proxy using gradle.properties:

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
# NOTE: this is not a typo.
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

There are separate settings for SOCKS.

Example 3: Configuring a SOCKS proxy using gradle.properties:

systemProp.socksProxyHost=www.somehost.org
systemProp.socksProxyPort=1080
systemProp.java.net.socks.username=userid
systemProp.java.net.socks.password=password

You may need to set other properties to access other networks.

Helpful references:

NTLM Authentication

If your proxy requires NTLM authentication, you may need to provide the authentication domain as well as the username and password.

There are 2 ways that you can provide the domain for authenticating to a NTLM proxy:

  • Set the http.proxyUser system property to a value like domain/username.

  • Provide the authentication domain via the http.auth.ntlm.domain system property.