50

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
  • 11,875
  • 18
  • 85
  • 108

3 Answers3

74

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
  • 568
  • 9
  • 18
Opal
  • 81,889
  • 28
  • 189
  • 210
  • 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. – Davoud Dec 29 '20 at 08:47
23

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
  • 12,947
  • 1
  • 71
  • 56
serv-inc
  • 35,772
  • 9
  • 166
  • 188
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
  • 9,388
  • 1
  • 65
  • 59