无法传输构件(https://repo.maven.apache.org/maven2):收到致命警报:协议版本 -> [帮助1]

47
我是 Maven 的新手,正在尝试在 Maven 中设置我的第一个项目,但是当我在 Eclipse 中执行“运行为 -> Maven install”时收到以下错误消息。以下是我的 settings.xml 和 pom.xml 文件。

Settings.xml

    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
 <localRepository>C:\Users\Iam\.m2\repository</localRepository>
  <profiles>
    <profile>
      <repositories>
    <repository>
        <id>central</id>
        <url>http://central.maven.org/maven2/</url>
        </repository>
    </repositories>
      <pluginRepositories>
      </pluginRepositories>
    </profile>
  </profiles>
</settings>

POM.XML

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
  <groupId>com.mytest</groupId> 
  <artifactId>MySpringBootMaven</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.11.RELEASE</version>
    </parent>


<build>
    <plugins>

      <plugin>
        <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>


        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.5</version><!--$NO-MVN-MAN-VER$-->
                <configuration>
                    <warnName>Test.war</warnName>
                </configuration>
            </plugin>
    </plugins>

</build>
</project>

错误信息:
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for org.springframework.boot:spring-boot-maven-plugin:jar:1.5.11.RELEASE
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:302)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:218)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:287)
    at org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.resolve(DefaultPluginDependenciesResolver.java:103)
    ... 27 more
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:1.5.11.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:287)
    ... 30 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:1.5.11.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version

如何解决“Received fatal alert: protocol_version”错误?我的Java版本是1.7,Maven版本是3.3.3。
11个回答

106
Sonatype 不再支持TLSv1.1及以下版本(自2018年6月18日起生效)。我猜测您正在使用TLSv1.1协议或以下版本。
我列出的文档给出了4个选项:
  1. 升级您的Java运行时,例如使用OpenJDK构建或支付Oracle支持费用
  2. 通过添加-Dhttps.protocols = TLSv1.2配置您的Java运行时以启用TLS 1.2
  3. 使用使用支持TLS 1.2的Java版本的存储库管理器
  4. 退回到http,直到您能够实现上述解决步骤之一。
我自己使用-Dhttps.protocols = TLSv1.2作为VM参数来修复它。

3
太好了,谢谢!我已经将我的Java版本更新到8,问题现在已解决。 - SimbuStar
2
谢谢提醒关于Java8的事情。在我的Mac上,我同时安装了Java7和Java8,这就是为什么我会遇到Maven错误的原因。错误信息非常误导人! - laishiekai
9
另一种解决方案是将"-Dhttps.protocols=TLSv1.2"设置为"MAVEN_OPTS"环境变量,这样maven就可以将这个jvm参数传递给底层的Java7运行时,用于构建你的应用程序。 - Mert Z.
有人能建议如何在Jenkins中配置相同的设置吗? - Sushant

17

对于永久解决方案(大多数情况下适用于Java 7),请按照以下步骤操作:

在您构建目录中(您执行mvn命令的目录)添加目录:.mvn(在命令提示符中使用mkdir .mvn创建)

然后在其中创建文件:jvm.config

并将以下行放入文件中:

-Dhttps.protocols=TLSv1.2


当我从构建目录中运行Maven时,这对我很有效。 - Ed Bayiates
2
如果上述提示无效,只需在mvn命令中添加选项-Dhttps.protocols=TLSv1.2,如下所示:mvn install -Dhttps.protocols=TLSv1.2 - eminemence
以上的解决方案正是我所寻找的,并且它非常有效 :) - irshad.ahmad

11

最简单的解决方案是配置JVM运行参数。在Eclipse中,您可以按照以下步骤进行操作:

进入窗口 > 首选项 > Java > 已安装的JRE, 点击您用于项目的已安装的JRE/JDK

在右侧点击“编辑”,并在默认VM参数输入框中添加 -Dhttps.protocols=TLSv1.2

请参阅截图:

截图


9

您正在尝试安装的软件包不支持TLS1.1,而您可能默认使用TLS 1.1。通过将-Dhttps.protocols = TLSv1.2添加到Maven Build命令中以配置Java运行时以启用TLS 1.2可以解决该问题。

例如:mvn clean install -Dhttps.protocols=TLSv1.2


1
它解决了我的问题。谢谢。 - Aditya Goel

5

我将Java 1.7升级到Java 1.8,但遇到了相同的错误。

为了解决这个问题,我使用mvn -version检查了mvn版本,并发现JAVA_HOME仍在使用Java 1.7。我将环境变量中的JAVA_HOME更改为指向JDK中的Java 1.8 jre。

希望这能帮助到某些人。


4
我将我的settings.xml文件设置在.m2目录中,就像这里的一个文件一样:https://github.com/alipay/sofa-rpc/pull/190/files。然后执行mvn install,所有依赖项开始下载。我以前没有settings.xml文件,也没有使用任何代理。希望对某些人有所帮助。
注:我使用的是jdk 1.7和Maven 3.3.9。

1
我通过在位于C驱动器的用户文件夹中的.m2文件夹中添加settings.xml文件,并通过右键单击pom.xml -> Maeven -> Update Project来更新项目,解决了SpringToolSuit中的此错误。
确保选择强制更新快照/发布。

0

它需要两个步骤:配置JVM运行时参数以及拥有一个settings.xml文件,我两者都做了之后它就可以工作了。仅更新JVM运行时参数是没有帮助的。


你在settings.xml中添加了什么才使它工作? - riroo

0

我曾经遇到同样的问题,尝试了这里大部分的答案但仍然没有解决。我的问题是IDE上的代理设置。因此,记得检查代理设置也很重要。文件 > 设置 > 系统设置 > HTTP代理 - 选择自动检测代理设置。


0
在我的情况下,Eclipse 中的 Maven 依赖自动更新被禁用了。
解决方案:
前往 Windows->Preferences->Maven
并取消勾选复选框

"不要自动从远程仓库更新依赖项"

然后更新项目
右键单击项目->maven->更新项目


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接