IntelliJ重新加载Gradle项目时触发prepareKotlinBuildScriptModel错误
Gradle同步(重新加载项目/变更)报错:TLS握手失败+不使用自定义distributionUrl
问题场景
- 执行「重新加载所有Gradle项目」或「加载Gradle变更」时触发同步错误,但常规插件任务、Gradle Wrapper运行完全正常
- 已排查企业代理配置,无效;同配置的其他项目无此问题
- 同步操作未遵循
gradle-wrapper.properties中配置的自定义ArtifactorydistributionUrl,反而请求官方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配置同步
- 打开IDE设置(File → Settings / Ctrl+Alt+S)
- 进入
Build, Execution, Deployment → Build Tools → Gradle - 确认「Gradle user home」路径正确;将「Build and run using」「Run tests using」都设为「Gradle Wrapper」
- 勾选「Use Gradle from 'gradle-wrapper.properties' file」
- 重启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的代理配置
- 打开IDE设置
Appearance & Behavior → System Settings → HTTP Proxy - 确保代理地址、端口、认证信息与
gradle.properties中配置的systemProp.http.proxyHost等参数完全一致 - 点击「Check connection」验证能否正常访问
services.gradle.org(若必须通过代理访问)
- 打开IDE设置
手动指定本地Gradle源码包(绕过网络请求)
- 从自定义Artifactory下载
gradle-8.1.1-src.zip到本地 - 在
gradle.properties中添加:
systemProp.gradle.distribution.src.url=file:///本地文件路径/gradle-8.1.1-src.zip替换
/本地文件路径为实际的文件路径,Windows系统需使用file:///C:/xxx/xxx.zip格式- 从自定义Artifactory下载
内容的提问来源于stack exchange,提问作者Steep
相关产品推荐
相关产品推荐

