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

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

 

1 背景

 

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

 

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 显示详细的错误信息如下:

 

Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
 at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
 at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
 at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
 at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
 at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
 at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
 at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
 at com.squareup.okhttp.Connection.connectTls(Connection.java:235)
 at com.squareup.okhttp.Connection.connectSocket(Connection.java:199)
 at com.squareup.okhttp.Connection.connect(Connection.java:172)
 at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367)
 at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
 at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
 at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)
 at com.squareup.okhttp.Call.getResponse(Call.java:267)
 at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
 at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
 at com.squareup.okhttp.Call.execute(Call.java:79)
 at io.takari.aether.okhttp.OkHttpAetherClient.execute(OkHttpAetherClient.java:167)
 at io.takari.aether.okhttp.OkHttpAetherClient.get(OkHttpAetherClient.java:113)
 at io.takari.aether.connector.AetherRepositoryConnector$GetTask.resumableGet(AetherRepositoryConnector.java:600)
 at io.takari.aether.connector.AetherRepositoryConnector$GetTask.run(AetherRepositoryConnector.java:453)
 at io.takari.aether.connector.AetherRepositoryConnector.get(AetherRepositoryConnector.java:304)
 ... 34 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[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 协议了

 


eclipse maven mvn install 报错 Received fatal alert: protocol_version 解决方案 (JDK7)_第1张图片
 

 

由于我的同事, 使用的 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 Protocols TLSv1.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 加入或者改成如下:

 


	
		central
				
		http://repo1.maven.org/maven2
					
	

 

 下面是相关位置代码:

 

		
	
		maven-home
		
			
				central
				https://repo1.maven.org/maven2
				
					true
					warn
				
				
					false
				
			
		

	
		
			central			
			http://repo1.maven.org/maven2			
			
	

 

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 

 

或者在相关脚本中加入:

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

你可能感兴趣的:(eclipse,Maven)