How can I use gradlew (the Gradle wrapper) behind a proxy?

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

Problem is that i am behid a proxy.

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 ?

You can set system properties within your gradlew script by using one the environment variables DEFAULT_JVM_OPTS, JAVA_OPTS or GRADLE_OPTS.

DEFAULT_JVM_OPTS="-Dhttp.proxyHost=www.somehost.org -Dhttp.proxyPort=8080 -Dhttp.proxyUser=userid -Dhttp.proxyPassword=password"
1 Like

Thanks

when i do not use any options and i used gradlew.bat as it is i get

C:\Downloads\glaforge-bloogaey-3cde055>gradlew Downloading http://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-3-b in.zip Exception in thread “main” java.net.ConnectException: Connection refused: connect…

when i tried your solution by modifying gradlew.bat by adding this:

set GRADLE_OPTS=%JAVA_OPTS% -Dorg.gradle.wrapper.properties="%WRAPPER_PROPERTIES%" -Dhttp.proxyHost=x.x.x.x -Dhttp.proxyPort=x -Dhttp.proxyUser=x -Dhttp.proxyPassword=x

then i get

C:\Downloads\glaforge-bloogaey-3cde055>gradlew Downloading http://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-3-b in.zip Exception in thread “main” java.io.IOException: Server returned HTTP response co de: 407 for URL: http://repo.gradle.org/gradle/distributions/gradle-1.0-mileston e-3-bin.zip

What am i doing wrong here ?

Thanks

I come back with a link i discovered at stackoverflow which describe the same problem…:

http://stackoverflow.com/questions/5991194/gradle-proxy-configuration

http://issues.gradle.org/browse/GRADLE-1556

Apparenlty is still open the issue…

The links you give are outdated. Have you tried with the latest milestone?

I used gradlew.bat that came with gradle-wrapper.jar in a project that i took from github…there is a newer version of gradle-wrapper.jar ?

The wrapper Jar doesn’t determine the version of Gradle. You have to update gradle-wrapper.properties to point to the latest Gradle distribution.

But the problem seem to be in the gradlew code:

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon n.java:1436)

at org.gradle.wrapper.Download.downloadInternal(Download.java:49)

at org.gradle.wrapper.Download.download(Download.java:37)

at org.gradle.wrapper.Install.createDist(Install.java:54)

at org.gradle.wrapper.Wrapper.execute(Wrapper.java:80)

at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:37)

This is the property you say i should change ?

distributionUrl=http://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-3-bin.zip

that is ok…the problem is on authentication like is describen on stackoverflow…like user name and pass are not recognized

Downloading http://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-3-b in.zip

Exception in thread “main” java.io.IOException: Server returned HTTP response co de: 407 for URL: http://repo.gradle.org/gradle/distributions/gradle-1.0-mileston e-3-bin.zip

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon nection.java:1436)

at org.gradle.wrapper.Download.downloadInternal(Download.java:49)

at org.gradle.wrapper.Download.download(Download.java:37)

at org.gradle.wrapper.Install.createDist(Install.java:54)

at org.gradle.wrapper.Wrapper.execute(Wrapper.java:80)

at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:37)

Sorry, I didn’t get that the Gradle download is the problem. What you could do is to generate the wrapper with milestone 7 and check if the problem still exists.

Ok …how can i generate it ?

…just a small direction …

I have downloaded lates gradle with sources…

Add and execute this task:

task wrapper(type: Wrapper) {
    gradleVersion = '1.0-milestone-7'
}

Manages to do this and i have the new gradle-wrapper.jar and new prop file but still the same problem.

c:\Downloads\glaforge-bloogaey-3cde055>gradlew Downloading http://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-7-b in.zip

Exception in thread “main” java.io.IOException: Server returned HTTP response co de: 407 for URL: http://repo.gradle.org/gradle/distributions/gradle-1.0-mileston e-7-bin.zip

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon nection.java:1436)

at org.gradle.wrapper.Download.downloadInternal(Download.java:49)

at org.gradle.wrapper.Download.download(Download.java:37)

at org.gradle.wrapper.Install.createDist(Install.java:58)

at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:117)

at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:53)

Does the Download.downloadInternal take into consideration the username and password i set via -D propety

set GRADLE_OPTS=%JAVA_OPTS% -Dorg.gradle.wrapper.properties="%WRAPPER_PROPERTIES%" -Dhttp.proxyHost=158.169.xxx.xxx-Dhttp.proxyPort=80xx -Dhttp.proxyUser=xxx -Dhttp.proxyPassword=xxx

It looks like is the same problem as described on the link i posted above on stackoverflow but this time is for the gradle wrapper not for gradle itself.

The problem is already solved for Gradle itself, but apparently it isn’t solved for the Wrapper.

Peter’s right. The Gradle Wrapper uses regular java.net.URL to download the Gradle distro. The URL class supports ‘http.proxyHost’ and ‘http.proxyPort’ out of the box, but requires extra configuration to handle proxy authorisation.

This is GRADLE-1679.

That’s what i discovered and said as well…will do a local patch for myself and if it’s ok i submit for a patch (merge)

ok solved the problem for me…added the solution to http://issues.gradle.org/browse/GRADLE-1679 as comment.