gradle代理需要设置在指定的配置文件中,如果是系统层面的代理是不管用的,gradle还是会走直连。

官方文档:

https://docs.gradle.org/4.0/userguide/build_environment.html#N10D07
https://docs.gradle.org/current/userguide/build_environment.html#sec:accessing_the_web_via_a_proxy

设置代理的方式有三种:

全局代理配置:

$HOME/.gradle/gradle.properties

项目目录下设置代理:

gradle/wrapper/gradle-wrapper.properties

命令行设置代理:

gradle -Dhttps.proxyHost=10.3.132.54 -Dhttps.proxyPort=8080 -Dhttps.proxyUser=userid -Dhttps.proxyPassword=password -Dhttps.nonProxyHosts=*.nonproxyrepos.com|localhost


配置文件中设置代理的方式:

HTTP代理:

systemProp.http.proxyHost=10.3.132.54
systemProp.http.proxyPort=8118
#systemProp.http.proxyUser=userid
#systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.aliyun.com|localhost|127.0.0.1|10.3.0.0/16

HTTPS代理:

systemProp.https.proxyHost=10.3.132.54
systemProp.https.proxyPort=8118
#systemProp.https.proxyUser=userid
#systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.aliyun.com|localhost|127.0.0.1|10.3.0.0/16

Socks代理:

systemProp.socks.proxyHost=www.somehost.org
systemProp.socks.proxyPort=8080
#systemProp.socks.proxyUser=userid
#systemProp.socks.proxyPassword=password
systemProp.socks.nonProxyHosts=*.nonproxyrepos.com|localhost


命令行设置代理的方式:

HTTP代理:

gradle -Dhttp.proxyHost=10.3.132.54 -Dhttp.proxyPort=8080 -Dhttp.proxyUser=userid -Dhttp.proxyPassword=password -Dhttp.nonProxyHosts=*.nonproxyrepos.com|localhost

HTTPS代理:

gradle -Dhttps.proxyHost=10.3.132.54 -Dhttps.proxyPort=8080 -Dhttps.proxyUser=userid -Dhttps.proxyPassword=password -Dhttps.nonProxyHosts=*.nonproxyrepos.com|localhost

Socks代理:

gradle -Dsocks.proxyHost=10.3.132.54 -Dsocks.proxyPort=8080 -Dsocks.proxyUser=userid -Dsocks.proxyPassword=password -Dsocks.nonProxyHosts=*.nonproxyrepos.com|localhost


例:

gradle -Dhttps.proxyHost=10.3.132.54 -Dhttps.proxyPort=8118 -Dhttps.nonProxyHosts=*.aliyun.com|localhost|127.0.0.1|10.3.0.0/16