1. 程式人生 > >【原創】經驗分享(10)Could not transfer artifact org.apache.maven:maven. from/to central. Received fatal alert: protocol_version

【原創】經驗分享(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問題解決。