[GRADLE-1679] gradlew does not support HTTP proxy authentication Created: 20/Jul/11  Updated: 04/Jan/13  Resolved: 06/Feb/12

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.0-milestone-8

Type: Improvement
Reporter: Matt Stine Assignee: Daz DeBoer
Resolution: Fixed Votes: 2

Issue Links:
Duplicate
Duplicated by GRADLE-1556 Gradle does not support proxy authent... Resolved

 Description   

Gradle wrapper uses http.proxyHost and http.proxyPort to determine the proxy server to use. However, it does not support the http.proxyUser and http.proxyPassword parameters that are used for proxy authentication.



 Comments   
Comment by Matt Stine [ 20/Jul/11 ]

I cloned this issue in an attempt to upvote it since it was closed - I'm sorry if that is bad form.

I am currently unable to use gradlew behind a proxy w/ 1.0.0-milestone3. I have GRADLE_OPTS set, and things work fine when using an already installed version of Gradle. gradlew does not seem to consume the same proxy options.

Comment by Hans Dockter [ 21/Jul/11 ]

You can use system properties to make this work. To make them consumed by the wrapper, you could create a USER_HOME/.grade/gradle.properties

For the rest, see:
http://gradle.org/current/docs/userguide/tutorial_this_and_that.html#sec:accessing_the_web_via_a_proxy

You could also add them as -D command line arguments.

GRADLE_OPTS is not taken into consideration by the JVM that runs the wrapper.

Comment by Matt Stine [ 21/Jul/11 ]

Hmmm...have tried the USER_HOME/.gradle/gradle.properties route and it does not seem to work either for the wrapper. Same 407 error response.

Comment by Hans Dockter [ 21/Jul/11 ]

The logic for this can be found here:

https://github.com/gradle/gradle/blob/master/subprojects/wrapper/src/main/java/org/gradle/wrapper/GradleWrapperMain.java

https://github.com/gradle/gradle/blob/master/subprojects/wrapper/src/main/java/org/gradle/wrapper/SystemPropertiesHandler.java

Not sure what is going wrong.

Comment by Daz DeBoer [ 23/Jan/12 ]

If you're getting a 407 response, it's because your proxy server requires authentication. Proxy Authentication is not currently supported for the Gradle Wrapper.
I'll change the title of this issue to reflect this.

Comment by Cristian [ 24/Jan/12 ]

I modified GradleWrapperMain added

 
private static void addSystemProperties(File rootDir) {
		System.getProperties().putAll(
				SystemPropertiesHandler.getSystemProperties(new File(
						gradleUserHome(), "gradle.properties")));
		System.getProperties().putAll(
				SystemPropertiesHandler.getSystemProperties(new File(rootDir,
						"gradle.properties")));
		if (System.getProperty("http.proxyUser") != null) {			
			Authenticator.setDefault(new Authenticator() {
				@Override
				protected PasswordAuthentication getPasswordAuthentication() {
					return new PasswordAuthentication(System
							.getProperty("http.proxyUser"), System.getProperty(
							"http.proxyPassword", "").toCharArray());
				}
			});
		}
	}

and works for me...

Comment by Adam Murdoch [ 06/Feb/12 ]

Reopening to change fix-for field.

Comment by Luke Daley [ 15/May/12 ]

Is this issue really resolved? We are getting reports that this doesn't work.

See the bottom of http://forums.gradle.org/gradle/topics/_dhttp_nonproxyhosts_is_not_respected

Comment by Luke Daley [ 15/May/12 ]

Another: http://forums.gradle.org/gradle/topics/http_proxy_host_port_user_password_and_http_auth_preference_not_working_for_the_wrapper_on_a_download_for_gradle

Comment by Daz DeBoer [ 18/May/12 ]

I'm pretty sure this is working. Integration test is WrapperProjectIntegrationTest. This functionality uses java.net.URL to download, and supports authentication as described in http://docs.oracle.com/javase/6/docs/technotes/guides/net/http-auth.html

Comment by Ashutosh Kumar Nirala [ 21/May/12 ]

@Cristian
This method is not working on my machine (Ubuntu 11.10) I am sure I am doing sth wrong.
I was using it for building rosjava_core as directed at http://docs.rosjava.googlecode.com/hg/rosjava_core/html/building.html
Running $./gradlew install was giving exception as:-
Downloading http://services.gradle.org/distributions/gradle-1.0-milestone-9-bin.zip
Exception in thread "main" java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
....

Then I modified the jar file as directed by you ( I downloaded the code (zip) from https://github.com/gradle/gradle)
But still I am getting the same exception. The ./gradlew install, effectively runs the following command:-
java -Dhttp.proxyHost=<my proxy> -Dhttp.proxyPort=80 -Dhttp.proxyUser=<username> -Dhttp.proxyPassword=<password> -Dorg.gradle.appname=gradlew -classpath /home/nirala/ros_workspace/my_worksapce/rosjava_core/gradle/wrapper/gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain install

The class is getting modified, (I verified that by adding comments in extra lines I have added)
Any help is greatly appreciated.

Comment by Daz DeBoer [ 21/May/12 ]

@Ashutosh: what version of Gradle do you have running? If you're planning on upgrading to M9 (or later), then you won't need to make any changes to wrapper code. This issue was fixed in M8, and is working for a number of people.

However, because your current wrapper jar is built with an older version of gradle, you'll need to download the M9 distribution manually and rerun the 'wrapper' task so that your wrapper.jar is rebuilt with the latest code. Then you should be able to use the wrapper to download all future versions of gradle.
So to restate: you need a wrapper jar built with M8 or later, then it will support the http.proxyUser and http.proxyPassword system properties. An easy way to set these is in your wrapper.properties file like:
systemProp.http.proxyHost=my_proxy
systemProp.http.proxyPort=8081
systemProp.http.proxyUser=my_user
systemProp.http.proxyPassword=my_password

Comment by Ashutosh Kumar Nirala [ 24/May/12 ]

Hi Daz DeBoer,
Thanks for such a speedy reply and
I am extremely sorry for my late response,

So far I have not used any build tool like Ant etc, I need this for rosjava installation. Also I am not proficient with Ubuntu (Linux) or ROS which is complicating things for me.

Although by doing manual changes in the wrapper files I was able to run ./gradlew install and download files through gradle (it eventually failed at test, but that is I guess not related to installation of gradlew) kindly clarify my understanding on few things:-

1. I installed gradle from synaptic I am not sure about its version, on
$gradle -v
I got:-
------------------------------------------------------------
Gradle 1.0-milestone-3
------------------------------------------------------------

Gradle build time: Thursday, September 8, 2011 4:06:52 PM UTC
Groovy: 1.7.10
Ant: Apache Ant(TM) version 1.8.2 compiled on August 19 2011
Ivy: non official version
JVM: 1.6.0_23 (Sun Microsystems Inc. 20.0-b11)
OS: Linux 3.0.0-19-generic i386

I couldn't see this exact version on page : http://www.gradle.org/downloads
build time suggest its a very old version. Which version is this?

2. Also what is meant by rerunning the wrapper task in "rerun the 'wrapper' task so that your wrapper.jar is rebuilt with the latest code." what is wrapper task?
I mean wrapper.jar (which I guess is gradle-wrapper.jar) is a simple jar file, so can't I simply make it using eclipse. I mean it is independent of my gradle installation.

3. I am going through the userguide of gradle to understand the build process, is there a better way?

Thanks

Comment by Daz DeBoer [ 04/Jun/12 ]

http://gradle.org.

Once you've installed gradle, you should try running 'gradle' from the root of the rosjava project. If this doesn't work, please report your problem on the Gradle forums : http://forums.gradle.org

Comment by Ashutosh Kumar Nirala [ 05/Jun/12 ]

Hi Daz DeBoer,
I found out that I was setting proxy in the wrong properties file. I downloaded rosjava and it also had a gradle-wrapper.properties, but once I set the proxy and usernmae and password details at ~/.gradle/gradle-wrapper.properties it worked without any issues.

Generated at Wed Jun 30 12:01:41 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.