Gradle proxy setup

I need web access from Gradle through a proxy to use the Gradle / Artifactory integration for Jenkins. To reduce the possible causes of the problems, I manually add the Artifactory plugin to build.gradle and run it from the command line:

apply { apply from: "http://gradle.artifactoryonline.com/gradle/plugins/org/jfrog/buildinfo/build-info-extractor-gradle/1.0.1/artifactoryplugin-1.0.1.gradle" } 

Following this , I pointed out the following in .gradle / gradle.properties in my home directory:

 systemProp.http.proxyHost=hostname systemProp.http.proxyPort=8080 systemProp.http.proxyUser=de\\username systemProp.http.proxyPassword=xxx 

With the proxy server configuration specified above (which is known to work), it fails:

11: 33: 17.699 [ERROR] [org.gradle.BuildExceptionReporter] Called: java.io.IOException: the server responded with an HTTP response code: 407 for the URL: http://gradle.artifactoryonline.com/gradle/plugins/org/ jfrog / buildinfo / build-info-extractor-gradle / 1.0.1 / artifactoryplugin-1.0.1.gradle

I have two proxies to choose from, and each always responds with 407 (proxy authentication is required) and the other with 502 (Bad gateway), so obviously the proxyHost and proxyPort parameters are used.

Since the username (based on the Active Directory user) contains a backslash, I tried both \\ and \ , but didn't work. The specified user is different from the user who is registered on the machine and in Active Directory. These user credentials are not valid for the proxy server, so I need to specify a different user.

Setting the same options in the Jenkins or Artifactory GUI worked.

+132
java proxy windows-server-2008 gradle active-directory
May 13 '11 at 11:27
source share
15 answers

Using the very simple Java Request URL program, I was able to replicate the problem.

http.proxyUser and http.proxyPassword seem to be non-standard, albeit popular, options, since they are not described in the link to the Java link from the Gradle tutorial ; even if the Gradle manual mentions them.

It seems Java programs that want to support proxy authentication need to do this manually (and I was able to do this using the code on the linked page).




I sent this issue (and fix) to Gradle's issue tracking . Increased issue GRADLE-1556 was resolved in 1.0-milestone-8 (February 2012)

+22
May 13 '11 at 13:57
source share

Clarification of Daniel's answer:

Proxy Configuration Only HTTP

gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128

HTTPS only proxy configuration

gradlew -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129

HTTP and HTTPS Proxy Configuration

gradlew -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=3129

Proxy configuration with user and password

gradlew -Dhttp.proxyHost = 127.0.0.1 -Dhttp.proxyPort = 3128 - Dhttps.proxyHost = 127.0.0.1 -Dhttp s.proxyPort = 3129 -Dhttp s.proxyUser = user -Dhttp s.proxyPassword = pass [CN00] .proxyUser = pass [CN00] .proxyUser = pass [CN00] .proxyUser = pass [CN00] .proxyUser = pass user -Dhttp.proxyPassword = pass

worked for me (with gradle.properties either the homedir or dir of the project, the assembly still didn't work). Thanks for pointing out the issue to Gradle, which gave this workaround.

Upgrade You can also put these properties in gradle-wrapper.properties (see https://stackoverflow.com/a/1676767/ ... ).

+188
Mar 26 '14 at 16:01
source share

These are my gradle.properties, pay attention to the HTTPS part

 systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyPort=8118 systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=8118 
+51
May 6 '16 at 18:54
source share

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

 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 
+43
Nov 10 '15 at 18:06
source share

Try the following:

gradle -Dhttp.proxyHost=yourProxy -Dhttp.proxyPort=yourPort -Dhttp.proxyUser=usernameProxy -Dhttp.proxyPassword=yourPassoword

+23
Dec 15 '14 at 18:49
source share

For me, this work is added to 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 a port (usually 8080)

USER - user of my domain

PASSWORD, my password

In this case, the proxies for http and https are the same

+21
Sep 08 '16 at 13:57
source share

Create a file called gradle.properties in the project folder in which build.gradle is the build.gradle file. Add the following entry

  systemProp.http.proxyHost=proxy_url systemProp.http.proxyPort=proxy_port systemProp.http.proxyUser=USER systemProp.http.proxyPassword=PWD systemProp.https.proxyHost=proxy_url systemProp.https.proxyPort=proxy_port systemProp.https.proxyUser=USER systemProp.https.proxyPassword=PWD 

If you use DNS for the proxy, add it as systemProp.https.proxyHost=www.proxysite.com

For IP, just specify IP without http:// or https://
For more information, consult the Gradle white paper and configure proxies globally.

+10
Nov 08 '17 at 11:19 on
source share

Check in 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> 
+10
Sep 03 '18 at 14:17
source share

Based on SourceSimian answer; it worked on windows domain user accounts. Please note that the username does not have an included domain,

 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()) System.setProperty("${base}.proxyUser", "Username") System.setProperty("${base}.proxyPassword", "Password") } } } build.dependsOn setHttpProxyFromEnv 
+6
Dec 28 '17 at 19:03
source share

There are two ways to use Gradle behind a proxy server:

Add Command Line Arguments

(From the post of Guillaume Berchet)

Add these arguments to your gradle command:

 -Dhttp.proxyHost=your_proxy_http_host -Dhttp.proxyPort=your_proxy_http_port 

or these arguments if you are using https:

 -Dhttps.proxyHost=your_proxy_https_host -Dhttps.proxyPort=your_proxy_https_port 



Add lines to Gradle config file

in gradle.properties add the following lines:

 systemProp.http.proxyHost=your_proxy_http_host systemProp.http.proxyPort=your_proxy_http_port systemProp.https.proxyHost=your_proxy_https_host systemProp.https.proxyPort=your_proxy_https_port 

( gradle.properties file gradle.properties see the official documentation https://docs.gradle.org/current/userguide/build_environment.html.




EDIT: as @Joost said: a small but important detail that I initially overlooked: note that the actual hostname does NOT contain http:// part of the URL protocol ...

+1
Feb 02 '18 at 12:00
source share

An update of @sourcesimian and @ kunal-b answers , which dynamically sets a username and password if configured in the system properties.

Next, a username and password are set, if specified, or the host and port are simply added if no username and password are specified.

 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] //Get proxyHost,port, username, and password from http system properties // in the format http://username:password@proxyhost:proxyport def (val1,val2) = e.value.tokenize( '@' ) def (val3,val4) = val1.tokenize( '//' ) def(userName, password) = val4.tokenize(':') 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()) System.setProperty("${base}.proxyUser", userName.toString()) System.setProperty("${base}.proxyPassword", password.toString()) } } } 
+1
Mar 26 '18 at 18:14
source share

If you are behind a proxy server and use eclipse, go to Window Menu --> Preferences --> General --> Network Connections . Select Active Providers as a Guide.

In the "Proxy Entries" section, click "HTTPS", click "Edit" and add a proxy host and port. If a username and password are required, notify. It worked for me!

0
Aug 13 '15 at 9:57
source share

If this error with the HTTP 407 error occurred only with the selected packages, then the problem is not in the proxy server and Internet connection settings. You can even expose your PC to the Internet through NAT and still run into this problem. As a rule, at the same time you can download the necessary packages in the browser. The only solution I find: delete the .gradle folder in your profile (not in the project). After this synchronization, the project will take a lot of time, but everything will be restored.

0
Nov 03 '17 at 12:51 on
source share

In case I try to configure a proxy from Android Studio Appearance & Behavior => System Preferences => HTTP Proxy. But the proxy did not work, so I click not the proxy.

Checking NO PROXY will not remove proxy settings from gradle.properties (Global). You must delete it manually.

Therefore, I delete all properties, starting with systemProp, for example - systemProp.http.nonProxyHosts = *. Local, localhost

0
May 15 '18 at 13:03
source share

You should add the following configuration to gradle.configuration These are the proxy settings that you need to configure if you are working with a proxy.

Source: ( https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy )

And do not add "http.//or/humanhttps:emplar to systemProp.http.proxyHost only" www.host.com โ€œ. Also comment out systemProp.http.proxyUser or proxypassword if you do not need to enter the proxy.

 systemProp.proxySet=true systemProp.http.keepAlive=true systemProp.http.proxyHost=www.host.com systemProp.http.proxyPort=port systemProp.http.proxyUser=username_ifneeded systemProp.http.proxyPassword=password_needed systemProp.http.nonProxyHosts=local.net|some.host.com systemProp.https.keepAlive=true systemProp.https.proxyHost=host systemProp.https.proxyPort=port systemProp.https.proxyUser=username_ifneeded systemProp.https.proxyPassword=password_ifneeded systemProp.https.nonProxyHosts=local.net|some.host.com 
0
Jul 17 '19 at 13:44 on
source share



All Articles