Java 全局 gradle 代理设置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26523804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Global gradle proxy settings?
提问by peterh - Reinstate Monica
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 currentgradle.properties
file, but it works only in the actual project. But
是的,我知道当前文件中有systemProp.http.proxyHost
, ...etc 设置,但它仅适用于实际项目。但gradle.properties
- 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.
- 我不会在每个 gradle 项目中都设置它
- 并且我不会因为我的本地网络配置而更改项目的源代码。
So, is there any "global gradle.properties" file or so?
那么,是否有任何“全局 gradle.properties”文件左右?
采纳答案by Opal
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 withsystemProp
..
我们可以定义一个
gradle.properties
文件并在这个文件中设置属性。我们可以将文件放在我们的项目目录或<USER_HOME>/.gradle
目录中。在我们的主目录中的属性文件中定义的属性优先于在我们的项目目录中的文件中定义的属性。作为奖励,我们还可以在 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
回答by serv-inc
For an easy copy&paste solution of @Opal's answer
对于@Opal 答案的简单复制和粘贴解决方案
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=8080
add this to $HOME/.gradle/gradle.properties
(Linux, OSX, Unices) or %userprofile%\.gradle\gradle.properties
(Windows, as of @fty4).
将此添加到$HOME/.gradle/gradle.properties
(Linux、OSX、Unices)或%userprofile%\.gradle\gradle.properties
(Windows,从@fty4 开始)。
回答by LeOn - Han Li
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