Gradle proxy configuration Gradle proxy configuration java java

Gradle proxy configuration


Refinement over Daniel's response:

HTTP Only Proxy configuration

gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 "-Dhttp.nonProxyHosts=*.nonproxyrepos.com|localhost"

HTTPS Only Proxy configuration

gradlew -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129 "-Dhttp.nonProxyHosts=*.nonproxyrepos.com|localhost"

Both HTTP and HTTPS Proxy configuration

gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129 "-Dhttp.nonProxyHosts=*.nonproxyrepos.com|localhost"

Proxy configuration with user and password

gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 - Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129 -Dhttps.proxyUser=user -Dhttps.proxyPassword=pass -Dhttp.proxyUser=user -Dhttp.proxyPassword=pass -Dhttp.nonProxyHosts=host1.com|host2.com

worked for me (with gradle.properties in either homedir or project dir, build was still failing). Thanks for pointing the issue at gradle that gave this workaround. See reference doc at https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy

UpdateYou can also put these properties into gradle-wrapper.properties (see: https://stackoverflow.com/a/50492027/474034).


This is my gradle.properties, please note those HTTPS portion

systemProp.http.proxyHost=127.0.0.1systemProp.http.proxyPort=8118systemProp.https.proxyHost=127.0.0.1systemProp.https.proxyPort=8118


In my build.gradle I have the following task, which uses the usual linux proxy settings, HTTP_PROXY and HTTPS_PROXY, from the shell env:

task setHttpProxyFromEnv {    def map = ['HTTP_PROXY': 'http', 'HTTPS_PROXY': 'https']    for (e in System.getenv()) {        def key = e.key.toUpperCase()        if (key in map) {            def base = map[key]            def url = e.value.toURL()            println " - systemProp.${base}.proxy=${url.host}:${url.port}"            System.setProperty("${base}.proxyHost", url.host.toString())            System.setProperty("${base}.proxyPort", url.port.toString())        }    }}build.dependsOn setHttpProxyFromEnv