Gradle 同步错误:SSL 对等点错误关闭

Posted

技术标签:

【中文标题】Gradle 同步错误:SSL 对等点错误关闭【英文标题】:Gradle Sync Error: SSL peer shut down incorrectly 【发布时间】:2021-12-04 12:47:21 【问题描述】:

我正在使用 IntelliJ 来同步 Gradle。 Gradle 项目是由 IntelliJ 模板提供的,但错误仍然存​​在。

我已经尝试过:

    使用 android Studio 做同样的事情,同样的事情发生了。 重新安装 IntelliJ,没用。 清除代理设置,没用。我过去确实使用过 ***,但没有更改 IntelliJ 中的代理设置。

我的系统:MacOS Big Sur

所以这是错误:

FAILURE: Build failed with an exception.

* What went wrong:
Could not download junit-jupiter-api-5.7.0.jar (org.junit.jupiter:junit-jupiter-api:5.7.0)
Could not get resource 'https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar'.
Could not GET 'https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar'.
The server may not support the client's requested TLS protocol versions: (TLSv1.2). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.1/userguide/build_environment.html#gradle_system_properties
Remote host closed connection during handshake
SSL peer shut down incorrectly

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not download junit-jupiter-api-5.7.0.jar (org.junit.jupiter:junit-jupiter-api:5.7.0)
Could not get resource 'https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar'.
Could not GET 'https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar'.
The server may not support the client's requested TLS protocol versions: (TLSv1.2). You may need to configure the client to allow other protocols to be used. See: https://docs.gradle.org/7.1/userguide/build_environment.html#gradle_system_properties
Remote host closed connection during handshake
SSL peer shut down incorrectly

at org.jetbrains.plugins.gradle.model.ProjectImportAction.addBuildModels(ProjectImportAction.java:346)
    at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:127)

...[omitted numerous lines]

Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar'

Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://repo.maven.apache.org/maven2/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar'.

Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: The server may not support the client's requested TLS protocol versions: (TLSv1.2). You may need to configure the client to allow other protocols to be used.

Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(InputRecord.java:505)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:990)

这是我的 gradle 构建脚本:

plugins 
    id 'java'


group 'org.example'
version '1.0-SNAPSHOT'

repositories 
    mavenCentral()


dependencies 
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'


test 
    useJUnitPlatform()

万分感谢!!!!!!!!!

【问题讨论】:

有人可以帮忙吗? 【参考方案1】:

这是因为 Maven Central 和 Bintray 已宣布将停止对 TLS v1.1 及以下版本的支持

将 mavenCentral() 替换为 maven url = "http://repo.maven.apache.org/maven2" 并将 jcenter() 替换为 maven url = "http://jcenter.bintray.com"

欲了解更多信息:https://blog.gradle.org/unable-to-download-maven-central-bintray

【讨论】:

谢谢!但是如何更改 IntelliJ 中的请求协议?比如从 TLS v1.1 升级到 TLS v1.2?【参考方案2】:

尝试以“gradle -Dhttps.protocols=TLSv1.2 clean build”的形式运行构建任务 如果您使用 intellij 构建添加 Vm arg "-Dhttps.protocols=TLSv1.2"

【讨论】:

以上是关于Gradle 同步错误:SSL 对等点错误关闭的主要内容,如果未能解决你的问题,请参考以下文章

使用本地信任库时,Android HttpsUrlConnection javax.net.ssl.SSLException 连接因对等握手错误而关闭

Android Studio Gradle 构建失败。错误:原因:对等方未通过身份验证

javax.net.ssl.SSLException:连接由 4.4.2 设备上的对等方关闭(适用于 6.0.1)

javax.net.ssl.SSLException:读取错误:ssl=0x9524b800:系统调用期间的 I/O 错误,对等方重置连接

OkHttp3 hostnameVerifier 原因:javax.net.ssl.SSLException:读取错误:ssl=0xc8cf1fc8:系统调用期间的 I/O 错误,对等方重置连接

Go-sql-driver:关闭坏空闲连接:对等点重置连接(mysql)