Gradle Proxy Configuration

Gradle proxy configuration

Using a very simple "Request a URL" Java program, I was able to replicate the issue.

http.proxyUser and http.proxyPassword seem to be non-standard, albeit popular, options, as they're not described in the Java reference page linked from the Gradle tutorial; even though the Gradle manual mentions them.

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


I submitted this issue (and a fix) to the Gradle issue tracker. Raised issue GRADLE-1556 was resolved in 1.0-milestone-8 (Feb 2012)

How to set proxy server for gradle?

Gradle has it's own dependency management system similar to maven. I think parts of the gradle publish plugin are backed by maven in some way (not verified). Regardless you shouldn't have to worry about that level of depth, gradle will handle it. Your problem is setting up the proxy. You just need to set some variables in $projectDir/gradle.properties, example:

#http proxy setup
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

#https proxy setup
systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

reference: https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy

Global gradle proxy settings?

Yes it seems possible. See here, especially:

We can define a gradle.properties file and set the property in this
file. We can place the file in our project directory or in the
<USER_HOME>/.gradle directory. The properties defined in the property
file in our home directory take precedence over the properties defined
in the file in our project directory. As a bonus we can also define
system properties in a gradle.properties file, we only have to prefix
the property name with systemProp..

The gradle.properties files can be found at the following paths:

# windows gradle file
%userprofile%\.gradle\gradle.properties

# linux gradle file
~/.gradle/gradle.properties

AndroidStudio gradle proxy

In Android Studio -> Preferences -> Gradle, pass the proxy details as VM options.

Gradle VM Options
-Dhttp.proxyHost=www.somehost.org -Dhttp.proxyPort=8080 etc.

*In 0.8.6 Beta Gradle is under File->Settings (Ctrl+Alt+S, on Windows and Linux)

Gradlew behind a proxy

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

Android Studio Gradle proxy settings

If you want to use a proxy for a particular project, go to your project directory and locate “gradle.properties” file. It should be in the same directory as “build.gradle” file. If you don’t see one, create one. Make sure to create “gradle.properties” and not “gradle.properties.txt”.

Add your proxy info-

systemProp.http.proxyHost=some-proxy-host.com

systemProp.http.proxyPort=some-port

systemProp.https.proxyHost=some-proxy-host.com

systemProp.https.proxyPort= some-port

If you have authentication as well, add-

systemProp.http.proxyUser=userid

systemProp.http.proxyPassword=password

systemProp.https.proxyUser=userid

systemProp.https.proxyPassword=password

If you want all projects to have the same proxy setting-

Go to your user home directory. In Win 7, it would be “C:\Users\username”. Locate .gradle directory and drop “gradle.properties” file you created above in .gradle directory.

configure proxy for gradle-vfs plugin

One (my) solution is to add vfs options defining the Proxy parameters.
This could be more sophisticated e.g. by building a task to derive the parameters from the system environment, but this one works:

task download << {
mkdir downloadDir
vfs {
options 'vfs.http.proxyHost' : 'mylocalsquid.lokal'
options 'vfs.http.proxyPort' : '3128'
options 'vfs.https.proxyHost' : 'mylocalsquid.lokal'
options 'vfs.https.proxyPort' : '3128'
cp "zip:https://github.com/asciidoctor/asciidoctor-reveal.js/archive/${asciidoctorBackendVersion}.zip!asciidoctor-reveal.js-${asciidoctorBackendVersion}",
templateDir, recursive:true, overwrite:true
cp "zip:https://github.com/hakimel/reveal.js/archive/${revealjsVersion}.zip!reveal.js-${revealjsVersion}",
revealjsDir, recursive:true, overwrite:true
}
}

This was derived from the documentation at http://ysb33r.github.io/groovy-vfs/1.0/docs/product-documentation.html

How to prevent gradle from using proxy in IntelliJ IDEA?

When you add proxy in the intellij IDEA it automatically adds the proxy in gradle.properties but when you remove it from settings it's still there. open gradle.properties and remove the proxy.

It should be something like this:

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

There are 3 places gradle.properties can be placed (if an option is configured in multiple locations the last one wins)

gradle.properties in Gradle installation directory.

gradle.properties in project root directory.

gradle.properties in GRADLE_USER_HOME directory. (if you did not set GRADLE_USER_HOME in your environment variable, the default is USER_HOME/.gradle)

You can read more about it here

Gradle works with proxy settings but Gradle-wrapper does not. Why?

Copy paste your question's code in a new file inside your root project named "gradle.properties".

As an alternative, you can also add it inside your buildscript, as described in the relevant section of the gradle docs.

The file gradle/wrapper/gradle-wrapper.properties contains info about the wrapper itself and it is different from the file gradle.properties in your project's root folder. If you have modified that it would be best to return it to its original state.



Related Topics



Leave a reply



Submit