如何为gradle设置代理服务器?

问题描述 投票:0回答:2

我需要设置一个代理服务器,以便能够从我公司的网络使用gradle下载项目依赖项。我尝试为shell设置代理,但它不起作用,所以我认为这是因为命令,gradle使用下载这些依赖项,不使用 http_proxy 环境变量。

gradle 在下载项目依赖时使用哪些命令(如

wget
curl
)?我如何检查这些命令?我尝试了 --info 和 --debug 选项,但它只对每个文件说了类似的内容;

Download https://jcenter.bintray.com/com/android/tools/lint/lint/25.1.0/lint-25.1.0.pom
android gradle command-line android-gradle-plugin build.gradle
2个回答
47
投票

Gradle 有自己的依赖管理系统,类似于 Maven。我认为 gradle 发布插件的部分内容以某种方式由 Maven 支持(未验证)。不管怎样,你不必担心这个深度,gradle 会处理它。您的问题是设置代理。你只需要在$projectDir/gradle.properties中设置一些变量即可,例如:


#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

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


0
投票

在菜单栏中,单击“文件”>“设置”(在 macOS 上,单击“Android Studio”>“首选项”)。
  1. 在左侧窗格中,单击外观和行为 > 系统设置 > HTTP 代理。将出现 HTTP 代理页面。
  2. 选择自动检测代理设置以使用自动代理配置 URL 进行代理设置,或选择手动代理配置以自行输入每个设置。
  3. 单击“应用”或“确定”以使更改生效。
© www.soinside.com 2019 - 2024. All rights reserved.