【问题标题】:Gradle wrapper times out when using a proxy使用代理时 Gradle 包装器超时
【发布时间】:2022-11-10 17:44:05
【问题描述】:

这个问题专门针对Gradle 包装器而不是完整的 Gradle 安装。

我的公司强迫我使用代理来访问许多 url,而解决超时问题通常需要的只是配置任何试图访问所述 url 的东西以使用代理,之后我得到一个证书验证错误,我也必须这样做将站点的 SSL 证书添加到 Java 的密钥库中(以 this answer 为例说明如何执行后者)。

但是,使用 Gradle 包装器(版本 7.4.1+),我仍然会超时。
我搜索了一下,发现很多人似乎有这个问题。不过,他们中的大多数只需要在 gradle.properties 文件中配置代理(在 Windows 上,默认情况下在 %userprofile%\.gradle 中):

systemProp.http.proxyHost=the proxy host
systemProp.http.proxyPort=the port
systemProp.http.proxyUser=username (if authentication is needed)
systemProp.http.proxyPassword=password (if authentication is needed)
systemProp.https.proxyHost=the proxy host
systemProp.https.proxyPort=the port
systemProp.https.proxyUser=username (if authentication is needed)
systemProp.https.proxyPassword=password (if authentication is needed)

或者,他们必须从文件中删除错误的代理配置。
他们中的一些人通过使用以下属性增加 Gradle 的超时来解决问题:

systemProp.org.gradle.internal.http.connectionTimeout=300000
systemProp.org.gradle.internal.http.socketTimeout=300000

这些解决方案对我不起作用。为什么?

【问题讨论】:

    标签: gradle proxy gradle-wrapper


    【解决方案1】:

    我发现原因是gradle-wrapper 的源中的硬编码连接超时值。 See this issue in their Github;看来他们要为 7.6 版修复它。

    问题中提到的org.gradle.internal.http.connectionTimeoutorg.gradle.internal.http.socketTimeout 系统属性仅由Gradle“正确”考虑,而不是由包装器考虑。

    因此,在gradle.properties 文件中设置更长的超时等待时间是行不通的。如何在不从 Gradle 站点手动下载内容的情况下解决问题?
    一种方法是在更改超时后从源重新编译包装器。另一个更简单的解决方案是编辑已编译的 jar。您可以为此使用 Recaf 之类的东西。

    然后替换您正在使用的gradle-wrapper.jar 并重试。

    一旦包装器第一次设法下载“dist”,即使使用原始 jar,您也可能不会再遇到这个问题。

    如果您在第一次之后再次超时,那么您必须这样做以确保使用修改后的gradle-wrapper.jar 而不是原来的,例如在创建新项目时由 IDE 使用:

    • %userprofile%.gradlewrapperdistsgradle-<version>-bin<folder with a random-looking name>gradle-<version>lib
      例如在我的情况下是:
      C:Usersusername.gradlewrapperdistsgradle-7.4.2-bin8ivgl02cpt2ed3fh9dbalvx8gradle-7.4.2lib

    • 打开gradle-wrapper-<version>.jar 文件

    • 用修改后的替换其中的gradle-wrapper.jar

    是的,它是一个包含另一个类似名称的罐子的罐子。用修改后的 jar 替换外部的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 2013-04-15
      • 1970-01-01
      • 2021-02-27
      • 2023-04-05
      • 2014-09-08
      • 1970-01-01
      相关资源
      最近更新 更多