Failure to transfer org.apache.maven.plugins:maven-

最近换了一台电脑修改以前的老MAVEN项目,突然爆出了这个错误:

Failure to transfer org.apache.maven.plugins:maven-assembly-plugin:pom:3.1.0 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-assembly-plugin:pom:3.1.0 from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version    pom.xml    /tester    line 1    Maven Configuration Problem

分析:项目在原电脑正常运行,排除是项目有问题,那就只能是环境的问题,经过排查,发现maven无法下载jar吧,网页打开地址(https://repo.maven.apache.org/maven2),可以,排除网络的问题,经过多方搜查,原来是由于TLSv1.1 协议不安全, 出于PCI 安全标准的原因, 自2018-06-18起, maven Sonatype 中央仓库不再支持 TLSv1.1 以及以下的协议版本,原文参见 no longer supports TLSv1.1 and below  官方说明通过chrome security 面板看到, maven 中央仓库已经是  TLSv1.2 协议了。

da042fdb-3f6f-3b9f-b6c7-09e19588b111.jpg

下表格是 根据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

 

有两种解决方法:

第一种方法

    将jdk版本升级到jdk1.8,因为在1.8及以上版本,才会默认使用TLS1.2。

    注意:是本地JAVA_HOME配置的JDK8,不是开发工具配置或者项目配置的JDK8

第二种方法

        使用 http  去访问 maven  中央仓库

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

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

<pluginRepositories>  
    <pluginRepository>  
        <id>central</id> 
        <url>http://repo1.maven.org/maven2</url>  
    </pluginRepository>  
</pluginRepositories>  

 下面是相关位置代码:

<profiles>          
    <profile>  
        <id>maven-home</id>  
        <repositories>  
            <repository>  
                <id>central</id>  
                <url>https://repo1.maven.org/maven2</url>  
                <releases>  
                    <enabled>true</enabled>  
                    <checksumPolicy>warn</checksumPolicy>  
                </releases>  
                <snapshots>  
                    <enabled>false</enabled>  
                </snapshots>  
            </repository>  
        </repositories>  
  
    <pluginRepositories>  
        <pluginRepository>  
            <id>central</id>              
            <url>http://repo1.maven.org/maven2</url>              
            </pluginRepository>  
    </pluginRepositories>  
</profile>  

第三种方法

    通过添加 -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

 

参考 

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

转载于:https://my.oschina.net/zhongshg/blog/2990724

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值