You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ重新加载Gradle项目时触发prepareKotlinBuildScriptModel错误

Gradle同步(重新加载项目/变更)报错:TLS握手失败+不使用自定义distributionUrl

问题场景

  • 执行「重新加载所有Gradle项目」或「加载Gradle变更」时触发同步错误,但常规插件任务、Gradle Wrapper运行完全正常
  • 已排查企业代理配置,无效;同配置的其他项目无此问题
  • 同步操作未遵循gradle-wrapper.properties中配置的自定义Artifactory distributionUrl,反而请求官方https://services.gradle.org/distributions/gradle-8.1.1-src.zip,最终报TLS握手失败错误

简化错误日志

> Task :prepareKotlinBuildScriptModel UP-TO-DATE
Unexpected exception while resolving Gradle distribution sources: Could not resolve all files for configuration ':detachedConfiguration1'.
org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':detachedConfiguration1'.
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve gradle:gradle:8.1.1.
Required by:
    project :
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve gradle:gradle:8.1.1.
Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://services.gradle.org/distributions/gradle-8.1.1-src.zip'.
Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not HEAD 'https://services.gradle.org/distributions/gradle-8.1.1-src.zip'.
Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: The server may not support the client's requested TLS protocol versions: (TLSv1.2, TLSv1.3). You may need to configure the client to allow other protocols to be used.
Caused by: javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake
Caused by: java.io.EOFException: SSL peer shut down incorrectly

BUILD SUCCESSFUL in 3s

解决方案

  • 强制IntelliJ使用Gradle Wrapper配置同步

    1. 打开IDE设置(File → Settings / Ctrl+Alt+S)
    2. 进入Build, Execution, Deployment → Build Tools → Gradle
    3. 确认「Gradle user home」路径正确;将「Build and run using」「Run tests using」都设为「Gradle Wrapper」
    4. 勾选「Use Gradle from 'gradle-wrapper.properties' file」
    5. 重启IDE后重新执行同步操作
  • 配置Gradle支持兼容TLS协议
    在项目根目录的gradle.properties中添加以下配置:

    systemProp.jdk.tls.client.protocols=TLSv1.1,TLSv1.2,TLSv1.3
    systemProp.https.protocols=TLSv1.1,TLSv1.2,TLSv1.3
    

    或者在IDE的Gradle VM选项中直接添加参数:
    进入Settings → Build, Execution, Deployment → Build Tools → Gradle,在「Gradle VM options」中输入:

    -Djdk.tls.client.protocols=TLSv1.1,TLSv1.2,TLSv1.3 -Dhttps.protocols=TLSv1.1,TLSv1.2,TLSv1.3
    
  • 对齐IDE与Gradle的代理配置

    1. 打开IDE设置Appearance & Behavior → System Settings → HTTP Proxy
    2. 确保代理地址、端口、认证信息与gradle.properties中配置的systemProp.http.proxyHost等参数完全一致
    3. 点击「Check connection」验证能否正常访问services.gradle.org(若必须通过代理访问)
  • 手动指定本地Gradle源码包(绕过网络请求)

    1. 从自定义Artifactory下载gradle-8.1.1-src.zip到本地
    2. 在gradle.properties中添加:
    systemProp.gradle.distribution.src.url=file:///本地文件路径/gradle-8.1.1-src.zip
    

    替换/本地文件路径为实际的文件路径,Windows系统需使用file:///C:/xxx/xxx.zip格式


内容的提问来源于stack exchange,提问作者Steep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 19:47:47