Gradle HTTP 超時設(shè)置

cover

原文地址:https://alphahinex.github.io/2020/06/19/gradle-http-timeout-settings/


description: "The Missing Guide"
date: 2020.06.19 19:34
categories:
- Java
tags: [Java, Gradle]
keywords: Java, Gradle, timeout, Maven, dependency


在使用 Nexus 時,很罕見的遇到了超時問題:

> Unable to load Maven meta-data from http://localhost:8081/repository/test/io/github/alphahinex/example/0.1.2-SNAPSHOT/maven-metadata.xml.
   > Could not HEAD 'http://localhost:8081/repository/test/io/github/alphahinex/example/0.1.2-SNAPSHOT/maven-metadata.xml'.
      > Read timed out

經(jīng)確認(rèn),http://localhost:8081/repository/test/io/github/alphahinex/example/0.1.2-SNAPSHOT/maven-metadata.xml 是可以得到正確的響應(yīng)的,但是響應(yīng)時間比較長。

類似問題,在使用 JitPack 真香 中提到的,需要 JitPack 先進行構(gòu)建才能下載的依賴時,也可能會遇到。

增加超時時間就可以解決這個問題了,但現(xiàn)在 Gradle 的 文檔 實在有點無力吐槽,啥也找不著。

下面就是缺失的 ——

Gradle HTTP 超時設(shè)置文檔

Gradle v6.0.1 為例:

超時屬性及默認(rèn)超時時間在 JavaSystemPropertiesHttpTimeoutSettings.java#L26-L29 中:

public static final String CONNECTION_TIMEOUT_SYSTEM_PROPERTY = "org.gradle.internal.http.connectionTimeout";
public static final String SOCKET_TIMEOUT_SYSTEM_PROPERTY = "org.gradle.internal.http.socketTimeout";
public static final int DEFAULT_CONNECTION_TIMEOUT = 30000;
public static final int DEFAULT_SOCKET_TIMEOUT = 30000;

設(shè)置方式為:

命令行

$ ./gradlew build -Dorg.gradle.internal.http.socketTimeout=200000 -Dorg.gradle.internal.http.connectionTimeout=200000

配置文件

可在 gradle.properties 文件中,通過如下屬性進行配置:

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

參考資料

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容