Gradle重新安装后下载插件失败Readtimedout问题解决-创新互联-成都快上网建站

Gradle重新安装后下载插件失败Readtimedout问题解决-创新互联

究极大坑记录

10年积累的成都做网站、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先制作网站后付款的网站建设流程,更有鼎城免费网站建设让你可以放心的选择与我们合作。

在使用gradle进行构建kotlin项目时,项目所用依赖版本需要同步升级gradle版本。升级gradle版本后,gradle相关插件无法下载,反复timeout超时。

症状如下:

执行命令 gradle -i clean build 后,开始漫长的下载,然后失败:

注:-i 输出info日志

···
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-daemon-client/1.6.21/kotlin-daemon-client-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download3229902775242623156bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.5.0/kotlinx-coroutines-core-jvm-1.5.0.jar to /home/gradle/.gradle/.tmp/gradle_download4641936627994279297bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-scripting-jvm/1.6.21/kotlin-scripting-jvm-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download494830282772546834bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-scripting-common/1.6.21/kotlin-scripting-common-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download1696422611660593758bin
Downloading https://plugins.gradle.org/m2/org/apache/httpcomponents/httpcore/4.4.13/httpcore-4.4.13.jar to /home/gradle/.gradle/.tmp/gradle_download4613440834708635299bin
Downloading https://plugins.gradle.org/m2/commons-codec/commons-codec/1.11/commons-codec-1.11.jar to /home/gradle/.gradle/.tmp/gradle_download2487575175939797213bin
Downloading https://plugins.gradle.org/m2/org/antlr/antlr4-runtime/4.7.2/antlr4-runtime-4.7.2.jar to /home/gradle/.gradle/.tmp/gradle_download6382324853186276276bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-android-extensions/1.6.21/kotlin-android-extensions-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download4220946164289467454bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.21/kotlin-gradle-plugin-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download8922362898136375486bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-annotation-processing-gradle/1.6.21/kotlin-annotation-processing-gradle-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download5814495170295735856bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-allopen/1.6.21/kotlin-allopen-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download5601980945359803720bin
Downloading https://plugins.gradle.org/m2/com/github/gundy/semver4j/0.16.4/semver4j-0.16.4-nodeps.jar to /home/gradle/.gradle/.tmp/gradle_download852946283032974153bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-serialization/1.6.21/kotlin-serialization-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download1626230451081345482bin
Downloading https://plugins.gradle.org/m2/de/undercouch/gradle-download-task/4.1.1/gradle-download-task-4.1.1.jar to /home/gradle/.gradle/.tmp/gradle_download6256542535068677013bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.21/kotlin-gradle-plugin-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download5954417891870185544bin
Downloading https://plugins.gradle.org/m2/de/undercouch/gradle-download-task/4.1.1/gradle-download-task-4.1.1.jar to /home/gradle/.gradle/.tmp/gradle_download728142808400847166bin
Downloading https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-buildpack-platform/2.7.5/spring-boot-buildpack-platform-2.7.5.jar to /home/gradle/.gradle/.tmp/gradle_download831862798076802621bin
Downloading https://plugins.gradle.org/m2/com/google/guava/guava/29.0-jre/guava-29.0-jre.jar to /home/gradle/.gradle/.tmp/gradle_download619813813879009204bin
Downloading https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-loader-tools/2.7.5/spring-boot-loader-tools-2.7.5.jar to /home/gradle/.gradle/.tmp/gradle_download8684696057715265902bin
Downloading https://plugins.gradle.org/m2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar to /home/gradle/.gradle/.tmp/gradle_download2424574873631595032bin
Downloading https://plugins.gradle.org/m2/org/apache/commons/commons-compress/1.21/commons-compress-1.21.jar to /home/gradle/.gradle/.tmp/gradle_download3817600958676182743bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-project-model/1.6.21/kotlin-project-model-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download1066903375613597598bin
Downloading https://plugins.gradle.org/m2/org/springframework/spring-core/5.3.23/spring-core-5.3.23.jar to /home/gradle/.gradle/.tmp/gradle_download1376461757858186083bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-tooling-metadata/1.6.21/kotlin-tooling-metadata-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download7590992773190642664bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-gradle-plugin-api/1.6.21/kotlin-gradle-plugin-api-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download3175302369981791912bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-klib-commonizer-api/1.6.21/kotlin-klib-commonizer-api-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download6170193827890920603bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-gradle-plugin-model/1.6.21/kotlin-gradle-plugin-model-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download2299907172101919458bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-util-klib/1.6.21/kotlin-util-klib-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download1748056694111182114bin
Downloading https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.21/kotlin-gradle-plugin-1.6.21.jar to /home/gradle/.gradle/.tmp/gradle_download111253886770528735bin
[91m
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'yybs-ios-net'.
>Could not resolve all files for configuration ':classpath'.
   >Could not download kotlin-gradle-plugin-1.6.21.jar (org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21)
      >Could not get resource 'https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.21/kotlin-gradle-plugin-1.6.21.jar'.
         >Read timed out

* Try:
>Run with --stacktrace option to get the stack trace.
>Run with --debug option to get more log output.
>Run with --scan to get full insights.

* Get more help at https://help.gradle.org

这里 尝试在项目的build.gradle.kts/build.gradle中配置仓库,无果,依旧使用 https://plugins.gradle.org/m2/org/jetbrains的地址去下载。配置服务器代理地址,依然无效。
因为本地是可以拉取成功的,而本地从上面截图中地址下载一样是很慢的。
经过两天的漫长折磨后,我开始寻找我本地安装gradle时,是否有什么设置。

于是我想到我最开始使用gradle时,用过前同事的Gradle配置对本地gradle的配置进行过重写。在~/.gradle/init.gradle 文件中!!!

我的init.gradle如下:

allprojects {repositories {maven {url 'https://maven.aliyun.com/repository/public/'
        }
        maven {url 'https://maven.aliyun.com/repository/jcenter/'
        }


        all {ArtifactRepository repo ->if (repo instanceof MavenArtifactRepository) {def url = repo.url.toString()

                if (
url.startsWith('https://repo.maven.apache.org/maven2/') 
|| url.startsWith('https://repo.maven.org/maven2') 
|| url.startsWith('https://repo1.maven.org/maven2') 
|| url.startsWith('https://jcenter.bintray.com/')
|| url.startsWith('https://plugins.gradle.org/')
) {//project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                    remove repo
                }
            }
        }
    }

    buildscript {repositories {maven{url 'https://maven.aliyun.com/repository/public/'}

            maven {url 'https://maven.aliyun.com/repository/jcenter/'
            }

            maven {url 'https://maven.aliyun.com/repository/gradle-plugin/'
            }
            all {ArtifactRepository repo ->if (repo instanceof MavenArtifactRepository) {def url = repo.url.toString()
                    if ( 
url.startsWith('https://repo1.maven.org/maven2') 
|| url.startsWith('https://jcenter.bintray.com/')
|| url.startsWith('https://plugins.gradle.org/')
) {//project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                        remove repo
                    }
                }
            }
        }
    }

}

将它放在你的~/.gradle/下即可。

配置好后,再执行gradle -i clean build ,发现下载快了几十倍,下载地址也换成了ali的中央仓库。ok 问题解决。

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


文章标题:Gradle重新安装后下载插件失败Readtimedout问题解决-创新互联
网站路径:http://kswjz.com/article/dgdjop.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流