Gradlew behind a proxy

GradleGaelyk

Gradle Problem Overview


I have a sample from Gaelyk (called Bloogie) and it is using gradlew.

I am behind a proxy.

I've read gradle docs and found this:

gradle.properties

systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password

But I have no clue how to put this info into the wrapper gradlew. Any idea?

Gradle Solutions


Solution 1 - Gradle

All you have to do is to create a file called gradle.properties (with the properties you mentioned above) and place it under your gradle user home directory (which defaults to USER_HOME/.gradle) OR in your project directory.

Gradle (the wrapper too!!!) automatically picks up gradle.properties files if found in the user home directory or project directories.

For more info, read the Gradle user guide, especially at section 12.3: Accessing the web via a proxy

Solution 2 - Gradle

If you need https access behind a proxy, please consider defining also the same set of properties for systemProp.https.

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080

See https://stackoverflow.com/questions/22073440/cant-build-android-app-using-crashlytics-behind-vpn-and-proxy for more information.

Solution 3 - Gradle

Use this in prompt line:

gradle -Dhttp.proxyHost=***  -Dhttp.proxyPort=*** -Dhttp.proxyUser=**** -Dhttp.proxyPassword=****

Works here!

Solution 4 - Gradle

Add the below in your gradle.properties file and in your gradle/wrapper/gradle-wrapper.properties file if you are downloading the wrapper over a proxy

If you want to set these properties globally then add it in USER_HOME/.gradle/gradle.properties file

## Proxy setup
systemProp.proxySet=true
systemProp.http.keepAlive=true
systemProp.http.proxyHost=host
systemProp.http.proxyPort=port
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=local.net|some.host.com

systemProp.https.keepAlive=true
systemProp.https.proxyHost=host
systemProp.https.proxyPort=port
systemProp.https.proxyUser=username
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=local.net|some.host.com
## end of proxy setup

Solution 5 - Gradle

I could not get the proxy property to work until I set the https proxy:

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080

However I had to use the http property for user name and password:

systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password

Solution 6 - Gradle

This problem with the Gradle Wrapper has been fixed with Gradle 1.0-milestone-8. Give it a shot.

Solution 7 - Gradle

after of this JDK update, I couldn't use gradlew behind a proxy again. and finally I found a JDK has disabled Basic authentication for HTTPS tunneling by default. so I have to add this property for gradle.properties in addition to proxy settings

systemProp.jdk.http.auth.tunneling.disabledSchemes=""

I hope it would be helpful for someone who struggle same problem

Solution 8 - Gradle

I had same problem and first thing I did was to create gradle.properties. I had not such as file so I should create it with following content:

systemProp.http.proxyHost=proxy
systemProp.http.proxyPort=port
systemProp.http.nonProxyHosts=domainname|localhost
systemProp.https.proxyHost=proxy
systemProp.https.proxyPort=port
systemProp.https.nonProxyHosts=domainname|localhost

When I added them gradlew command works properly behind corporate proxy. I hope that it can be useful.

Solution 9 - Gradle

To add more nuances, for my case, when I have multiple gradle.properties files in both USER_HOME/.gradle and the project root, I encountered the authenticationrequired 407 error, with the bellow log:

CONNECT refused by proxy: HTTP/1.1 407 authenticationrequired

This caused my systemProp.https.proxyPassword and systemProp.http.proxyPasswordblank in the gradle.properties file under USER_HOME/.gradle, while the gradle.properties file under the project root remained password info.

Not sure the exact reason, But when I remove one gradle.properties in the project root and keep the file in the USER_HOME/.gradle, my case is resolved.

Solution 10 - Gradle

I was found that reading of properties from gradle.properties can be incorrect. In case line contains trail white space, gradle cannot find proxy. check your proxy file and cut whitespace at the end of line. Can be help

Solution 11 - Gradle

This was not working for me at first.
In my case, I had created what I thought was a USER_HOME/.gradle/gradle.properties file but ended up with a gradle.properties.txt file.

From the terminal window an ls command will show the full file names in the .gradle folder.

Then mv gradle.properties.txt gradle.properties

Solution 12 - Gradle

I have the same proxy issue while working with Cordova project.

To fix the issue, I have created a new gradle.properties file under the android folder of my Cordova project (hello/platforms/android), and added the code from your question

systemProp.http.proxyHost=proxy.yourproxysite.com
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=yourusername
systemProp.http.proxyPassword=password

Solution 13 - Gradle

Setting SSl proxy worked for me.

systemProp.http.proxyHost=proxy.yourproxysite.com
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=proxy.yourproxysite.com
systemProp.https.proxyPort=8080

Solution 14 - Gradle

> An excerpted answer from the linked thread below. It shows how to do > this more programtically. Hope it helps

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())
        }
    }
}

See this thread for more

Solution 15 - Gradle

After lots of struggling with this and banging my head against a wall, because nothing on my system was using a proxy: it turned out that my ** Android Emulator instance ** itself was secretly/silently setting a proxy for me via Android Emulator > Settings > Proxy and had applied these settings when playing around with it weeks earlier in order to troubleshoot an issue with Expo.

If anyone is having this issue, make sure you check 100% to see if indeed no custom proxy settings are being used via: ./gradlew installDebug --info --debug --stacktrace and searching for proxyHost in the log output to make sure of this. It may be your emulator.

Solution 16 - Gradle

The following applies when your gradle archive is mirrored behind the firewall (like mine..):

For some reason, I needed both of these lines:

gradle.properties:

systemProp.http.nonProxyHosts=*.localserver.co
systemProp.https.nonProxyHosts=*.localserver.co

EVEN though my download line started with https, such as below:

gradle-wrapper.properties:

distributionUrl=https\://s.localserver.co/gradle-7.0.1-bin.zip

It wasn't working in ANY other way... except only it worked if I used export JAVA_OPTS=-Dhttp.nonProxyHosts=localserver.co|etc.
Even though my environment variable no_proxy was already correctly set, it wasn't working without the two values in the above properties.

Solution 17 - Gradle

systemProp.http.proxyUser=userId
systemProp.http.proxyPassword=password

same with https......

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCrisView Question on Stackoverflow
Solution 1 - Gradlec_makerView Answer on Stackoverflow
Solution 2 - GradleJean LestangView Answer on Stackoverflow
Solution 3 - GradleRaphael VitorView Answer on Stackoverflow
Solution 4 - GradlesonamarunView Answer on Stackoverflow
Solution 5 - GradlejjungView Answer on Stackoverflow
Solution 6 - GradleBenjamin MuschkoView Answer on Stackoverflow
Solution 7 - GradleJavvanoView Answer on Stackoverflow
Solution 8 - GradleJanusz KujawaView Answer on Stackoverflow
Solution 9 - Gradlegiang nguyenView Answer on Stackoverflow
Solution 10 - GradleAlexanderView Answer on Stackoverflow
Solution 11 - GradleDan vView Answer on Stackoverflow
Solution 12 - GradleNaresh ChennuriView Answer on Stackoverflow
Solution 13 - GradleMadhu Kiran SeelamView Answer on Stackoverflow
Solution 14 - GradleNorbertView Answer on Stackoverflow
Solution 15 - GradleseenickcodeView Answer on Stackoverflow
Solution 16 - GradleJordan GeeView Answer on Stackoverflow
Solution 17 - Gradletech guy999View Answer on Stackoverflow