java - Gradle proxy configuration

ID : 20213

viewed : 29

Tags : javaproxyactive-directorywindows-server-2008gradlejava

Top 5 Answer for java - Gradle proxy configuration

vote vote

100

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

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

vote vote

88

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

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

80

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 
vote vote

70

For me, works adding this configuration in the gradle.properties file of the project, where the build.gradle file is:

systemProp.http.proxyHost=proxyURL systemProp.http.proxyPort=proxyPort systemProp.http.proxyUser=USER systemProp.http.proxyPassword=PASSWORD systemProp.https.proxyHost=proxyUrl  systemProp.https.proxyPort=proxyPort systemProp.https.proxyUser=USER systemProp.https.proxyPassword=PASSWORD 

Where : proxyUrl is the url of the proxy server (http://.....)

proxyPort is the port (usually 8080)

USER is my domain user

PASSWORD, my password

In this case, the proxy for http and https is the same

vote vote

55

Check out at c:\Users\your username\.gradle\gradle.properties:

systemProp.http.proxyHost=<proxy host> systemProp.http.proxyPort=<proxy port> systemProp.http.proxyUser=<proxy user> systemProp.http.proxyPassword=<proxy password> systemProp.http.nonProxyHosts=<csv of exceptions> systemProp.https.proxyHost=<proxy host> systemProp.https.proxyPort=<proxy port> systemProp.https.proxyUser=<proxy user> systemProp.https.proxyPassword=<proxy password> systemProp.https.nonProxyHosts=<csv of exceptions seperated by | > 

Top 3 video Explaining java - Gradle proxy configuration

Related QUESTION?