本文最后更新于 115 天前,其中的信息可能已经有所发展或是发生改变。
由于服务器所在的环境并非国际互联网环境,因此需要将代理运行在服务器上,而 Gradle 想要使用此代理,设置环境变量是无效的。
需要通过配置文件 ~/.gradle/gradle.properties:
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=7890
systemProp.http.proxyUser=xxx
systemProp.http.proxyPassword=xxx
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=7890
systemProp.https.proxyUser=xxx
systemProp.https.proxyPassword=xxx
但实际使用的时候报错:
Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
经过网上冲浪发现,JDK 默认禁止在隧道中用 Basic Auth 认证方式,而此处我正好使用的这种方式,因此还需要添加一行配置:
systemProp.jdk.http.auth.tunneling.disabledSchemes=""