47

Is there any way to simply set up a global, system-wide proxy for gradle?

Yes, I know there is a systemProp.http.proxyHost, ...etc settings in the current gradle.properties file, but it works only in the actual project. But

  • I won't set it up in every gradle project
  • and I won't change the source code of a project because of my local network configuration.

So, is there any "global gradle.properties" file or so?

peterh
  • 1
  • 15
  • 76
  • 99

3 Answers3

69

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 
fty4
  • 526
  • 9
  • 16
Opal
  • 76,740
  • 25
  • 177
  • 200
  • 1
    On Windows you can find it directly here: %userprofile%\.gradle\gradle.properties On Linux you'll find it here ~\.gradle\gradle.properties – fty4 Mar 19 '19 at 07:59
  • 1
    @fty4, you can edit my answer to contain the paths from your comment. – Opal Mar 19 '19 at 08:29
  • Thumbs up, for accessing user home easily put `%homepath%` in `Run` window. – D B Dec 29 '20 at 08:47
18

Copy & paste:

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=8080

to gradle global config = current user's gradle.properties

  • Linux/Mac/Unices: $HOME/.gradle/gradle.properties
    • eg: /Users/limao/.gradle/gradle.properties
  • Windows: %userprofile%\.gradle\gradle.properties

More details refer official doc Accessing the web through a HTTP proxy

Thanks to @Opal's answer, @fty4

crifan
  • 10,971
  • 1
  • 61
  • 46
serv-inc
  • 32,612
  • 9
  • 143
  • 165
2

Also do not forget the no proxy setting for the exception list, just in case

systemProp.https.nonProxyHosts=artifactory.yourCompany.com|localhost|*.nonproxyrepos.com

LeOn - Han Li
  • 8,022
  • 1
  • 57
  • 53