org.apache.maven.plugins:maven-resources-plugin:2.4.3Received fatal alert: protocol_version

转摘链接:https://feitianbenyue.iteye.com/blog/2429045

eclipse maven mvn install 报错 Received fatal alert: protocol_version 解决方案

1 背景

今天我们一个小伙伴同事说,  eclipse 项目运行 maven install , 下载 maven maven-surefire-plugin  插件时候报错,控制台提示信息:

Java代码 

 收藏代码

  1. Failed to read artifact descriptor for org.apache.maven.surefire:surefire-api:jar:2.20.1: Could not transfer artifact org.apache.maven.surefire:surefire-api:pom:2.20.1 from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version -> [Help 1]  

 

使用 mvn install -X 显示详细的错误信息如下:

 

Java代码 

 收藏代码

  1. Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version  
  2.  at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)  
  3.  at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)  
  4.  at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)  
  5.  at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)  
  6.  at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)  
  7.  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)  
  8.  at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)  
  9.  at com.squareup.okhttp.Connection.connectTls(Connection.java:235)  
  10.  at com.squareup.okhttp.Connection.connectSocket(Connection.java:199)  
  11.  at com.squareup.okhttp.Connection.connect(Connection.java:172)  
  12.  at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367)  
  13.  at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)  
  14.  at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)  
  15.  at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)  
  16.  at com.squareup.okhttp.Call.getResponse(Call.java:267)  
  17.  at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)  
  18.  at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)  
  19.  at com.squareup.okhttp.Call.execute(Call.java:79)  
  20.  at io.takari.aether.okhttp.OkHttpAetherClient.execute(OkHttpAetherClient.java:167)  
  21.  at io.takari.aether.okhttp.OkHttpAetherClient.get(OkHttpAetherClient.java:113)  
  22.  at io.takari.aether.connector.AetherRepositoryConnector$GetTask.resumableGet(AetherRepositoryConnector.java:600)  
  23.  at io.takari.aether.connector.AetherRepositoryConnector$GetTask.run(AetherRepositoryConnector.java:453)  
  24.  at io.takari.aether.connector.AetherRepositoryConnector.get(AetherRepositoryConnector.java:304)  
  25.  ... 34 more  
  26. [ERROR]   
  27. [ERROR]   
  28. [ERROR] For more information about the errors and possible solutions, please read the following articles:  
  29. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginReso  

 

2. 原因 

 

由于TLSv1.1 协议不安全, 出于PCI 安全标准的原因, 从2018-06-18起, maven Sonatype 中央仓库不再支持 TLSv1.1 以及以下的协议版本,原文参见 no longer supports TLSv1.1 and below  官方说明

 

通过chrome security 面板看到, maven 中央仓库已经是  TLSv1.2 协议了

 



 

 

由于我的同事, 使用的 jdk 是 1.7 , jdk1.7虽然支持TLS 1.2 但是默认是 disabled的, 所以就会出现上面的 Received fatal alert: protocol_version  异常 

 

下表格是 根据Oracle文档 各版本JDK默认使用的TLS协议:

 

 JDK 8
(March 2014 to present)
JDK 7
(July 2011 to present)
JDK 6
(2006 to end of 2013)
TLS ProtocolsTLSv1.2 (default)
TLSv1.1
TLSv1
SSLv3
TLSv1.2
TLSv1.1
TLSv1 (default)
SSLv3

TLS v1.1 (JDK 6 update 111+)
TLSv1 (default)
SSLv3

 

 

3. 解决方案

 

3.1 方案1 :   使用 http  去访问 maven  中央仓库

 

对于安全要求不严格的场景, 可以使用http 去访问maven 仓库

 

对于 plugin ,  可以在 setting .xml 加入或者改成如下:

 

Xml代码 

 收藏代码

  1. <pluginRepositories>  
  2.     <pluginRepository>  
  3.         <id>central</id>  
  4.                   
  5.         <url>http://repo1.maven.org/maven2</url>  
  6.                       
  7.     </pluginRepository>  
  8. </pluginRepositories>  

 

 下面是相关位置代码:

 

Xml代码 

 收藏代码

  1. <profiles>          
  2.     <profile>  
  3.         <id>maven-home</id>  
  4.         <repositories>  
  5.             <repository>  
  6.                 <id>central</id>  
  7.                 <url>https://repo1.maven.org/maven2</url>  
  8.                 <releases>  
  9.                     <enabled>true</enabled>  
  10.                     <checksumPolicy>warn</checksumPolicy>  
  11.                 </releases>  
  12.                 <snapshots>  
  13.                     <enabled>false</enabled>  
  14.                 </snapshots>  
  15.             </repository>  
  16.         </repositories>  
  17.   
  18.     <pluginRepositories>  
  19.         <pluginRepository>  
  20.             <id>central</id>              
  21.             <url>http://repo1.maven.org/maven2</url>              
  22.             </pluginRepository>  
  23.     </pluginRepositories>  
  24. </profile>  

 

3.1 方案2 :  升级 jdk 到1.8

 

jdk1.8  TLS 1.2 默认是 enable ,不会出现这个异常

 

PS: 这个代价可以有点大, 尤其是一些老的项目, 不是说升就可以升的

 

 

方案3:  通过添加 -Dhttps.protocols=TLSv1.2 , 配置 java runtime 参数,来 enable TLS 1.2

 

如果你是jdk 1.7 (尤其是 1.7.0_131-b31 以前的版本)你可以使用以下command line:

 

mvn -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 <goals>

 

或者在相关脚本中加入:

export MAVEN_OPTS=-Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2

 

如果你是 1.6 的版本, sorry , 只能使用http 模式, 虽然有部分jdk 1.6 小版本声称支持  TLS 1.2,参见

Changes in 6u115 b32 TLS v1.2 support now available

 

4. 参考 

 

https://central.sonatype.org/articles/2018/May/04/discontinued-support-for-tlsv11-and-below/

 

https://stackoverflow.com/questions/50946420/could-not-transfer-artifact-https-repo-maven-apache-org-maven2-received-fat/50956622

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值