简体   繁体   English

全局 gradle 代理设置?

[英]Global gradle proxy settings?

Is there any way to simply set up a global, system-wide proxy for gradle?有没有办法简单地为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.是的,我知道当前gradle.properties文件中有一个systemProp.http.proxyHost ,...等设置,但它仅适用于实际项目。 But

  • I won't set it up in every gradle project我不会在每个 gradle 项目中都设置它
  • 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?那么,是否有任何“全局 gradle.properties”文件左右?

Yes it seems possible.是的,这似乎是可能的。 See here , especially:这里,特别是:

We can define a gradle.properties file and set the property in this file.我们可以定义一个gradle.properties文件并在这个文件中设置属性。 We can place the file in our project directory or in the <USER_HOME>/.gradle directory.我们可以将文件放在我们的项目目录或<USER_HOME>/.gradle目录中。 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 ..作为奖励,我们还可以在 gradle.properties 文件中定义系统属性,我们只需要在属性名称前加上systemProp ..

The gradle.properties files can be found at the following paths: gradle.properties 文件可以在以下路径中找到:

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

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

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 gradle global config = current usergradle.properties

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

More details refer official doc Accessing the web through a HTTP proxy更多细节参考官方文档通过 HTTP 代理访问网络

Thanks to @Opal's answer , @fty4感谢@Opal的回答@fty4

Also do not forget the no proxy setting for the exception list, just in case也不要忘记例外列表的no proxy设置,以防万一

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM