如何在命令行中使用带 gradle 的袜子进行依赖解析?

How to use socks with gradle for dependency resolving, in command line?

当没有代理服务器无法访问 jcenter 时,为了解决依赖关系,我想使用 socks 而不是 http 代理,如何在命令行中使用它? 我知道如何使用 http 代理:

-Dhttp.proxyHost=yourProxy -Dhttp.proxyPort=yourPort  
-Dhttp.proxyUser=usernameProxy -Dhttp.proxyPassword=yourPassoword

我找到了答案,你可以在这里使用:

./gradlew -DsocksProxyHost=yourHost 
-DsocksProxyPort=yourHostPort your-command

使用上面你可以设置袜子主机和端口。

参考https://discuss.gradle.org/t/how-can-i-set-gradle-proxy-to-socks/15508
在项目 window 中,范围从 Android 更改为 Project
然后打开 gradle.properties 并添加这一行:

org.gradle.jvmargs=-DsocksProxyHost=yourHostIP -DsocksProxyPort=yourHostPort

Sync 项目。

Gradle 只有关于 how to use HTTP(s) proxy, however in the ant source code 它提到的文档,关于如何设置 SOCKS 代理的信息已经足够了。

将下面两行添加到gradle.properties配置文件中就大功告成了。

systemProp.socksProxyHost=your socks proxy ip
systemProp.socksProxyPort=your socks proxy port

SOCKS 配置名称(socksProxyHost 和 socksProxyPort)的格式不同于 HTTP 代理主机和端口配置(http.proxyHost 和 http.proxyPort)。

我可能来晚了一点,但我发现在 ubuntu/Linux 中代理设置缓存在 ~/.gradle/gradle.properties 中,我还发现这gradle.properties 与 android studio 中您的应用中的不同。 所以你需要在那里编辑凭据。

执行 vim ~/.gradle/gradle.properties 并在那里编辑凭据。 在我的例子中,我使用的是袜子代理,所以我注释掉了所有的 http 和 https 代理主机和端口,并为袜子添加了一个。它看起来像这样

`systemProp.socks5ProxyHost=127.0.0.1

systemProp.socks5ProxyPort=1080`

之后我能够同步 gradle。