【原创】经验分享(10)Could not transfer artifact org.apache.maven:maven. from/to central. Received fatal alert: protocol_version

maven编译工程报错

[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:add-source (scala-compile-first) on project trade: Execution scala-compile-first of goal net.alchim31.maven:scala-maven-plugin:3.2.2:add-source failed: Plugin net.alchim31.maven:scala-maven-plugin:3.2.2 or one of its dependencies could not be resolved: Failed to collect dependencies at net.alchim31.maven:scala-maven-plugin:jar:3.2.2 -> org.apache.maven:maven-core:jar:3.0.4 -> org.apache.maven:maven-model:jar:3.0.4: Failed to read artifact descriptor for org.apache.maven:maven-model:jar:3.0.4: Could not transfer artifact org.apache.maven:maven-model:pom:3.0.4 from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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/PluginResolutionException

但是手工通过浏览器访问maven仓库一切正常

手工下载放到本地repository,然后再编译,这个错没了,又报下一个错,这么多包一个一个手工下载实在伤不起,

wtf,仔细一看,报错还有一句:Received fatal alert: protocol_version

原来是因为这个,官网地址:https://central.sonatype.org/articles/2018/May/04/discontinued-support-for-tlsv11-and-below/ 

这里粘贴一下answer:

If you are using http to access Central, or Java 8+ with https urls, you are not affected.

If you are on Java 7, it supports TLS 1.2 but it is disabled by default in versions before 1.7.0_131-b31, and the following Apache Maven workaround functions for older Java 7 users:

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

or add the following to your environment or build script:

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

If you are on Java 6, you will need to switch back to http or upgrade to a more modern Java version. Very recent versions of Java 6 claim to have TLS 1.2 support, but we have not confirmed it yet. 

原来是因为maven中央仓库不再支持TLSv1.1导致,jdk改为1.8问题解决。

 

相关文章