Java 无法传输工件(https://repo.maven.apache.org/maven2):收到致命警报:protocol_version -> [Help 1]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50946420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:53:43  来源:igfitidea点击:

Could not transfer artifact (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version -> [Help 1]

javamaven

提问by SimbuStar

I am new to Maven and trying to setup my first project in Maven but receiving the below error message when I am doing " Run as -> Maven install " in Eclipse. Below is my settings.xml and pom.xml

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

Settings.xml

设置.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

POM文件

<?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>

Error message:

错误信息:

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

How to resolve the Received fatal alert: protocol_version ? My java version is 1.7 and maven version is 3.3.3

如何解决接收到的致命警报:协议版本?我的 java 版本是 1.7,maven 版本是 3.3.3

采纳答案by Eric

Sonatype no longer supports TLSv1.1 and below(effective, June 18th, 2018). My guess is that you are using TLSv1.1 protocol or below.

Sonatype不再支持 TLSv1.1 及更低版本(2018 年 6 月 18 日生效)。我的猜测是您使用的是 TLSv1.1 或以下协议。

The documentation I listed gives you 4 options:

我列出的文档为您提供了 4 个选项:

  1. Upgrade your Java runtime, for example with OpenJDK builds or Oracle paying support
  2. Configure your Java runtime to enable TLS 1.2 by adding -Dhttps.protocols=TLSv1.2
  3. Use a repository manager that uses a Java version supporting TLS 1.2
  4. Revert back to http until you can acheive one of the above remediation steps.
  1. 升级您的 Java 运行时,例如使用 OpenJDK 构建或 Oracle 付费支持
  2. 通过添加 -Dhttps.protocols=TLSv1.2 配置您的 Java 运行时以启用 TLS 1.2
  3. 使用支持 TLS 1.2 的 Java 版本的存储库管理器
  4. 恢复到 http,直到您可以完成上述修复步骤之一。

I fixed it myself by just using -Dhttps.protocols=TLSv1.2 as a VM argument.  

我自己通过使用 -Dhttps.protocols=TLSv1.2 作为 VM 参数来修复它。  

回答by Yoav R.

For a permanent solution(mostly required in Java 7) - in you build directory(where you do the mvncommand from) add directory:

对于永久解决方案(在 Java 7 中主要需要) - 在您构建目录(您mvn从中执行命令的位置)中添加目录:

.mvn(in cmd mkdir .mvn)

.mvn(在 cmd 中mkdir .mvn

and in it create file

并在其中创建文件

jvm.config

jvm.config

and in put the following line:

并输入以下行:

-Dhttps.protocols=TLSv1.2

-Dhttps.protocols=TLSv1.2

回答by Georgina Diaz

I set my settings.xmlfile in the .m2 directory just as the one here: https://github.com/alipay/sofa-rpc/pull/190/files

我在 .m2 目录中设置了我的settings.xml文件,就像这里的一样:https: //github.com/alipay/sofa-rpc/pull/190/files

Then exec mvn installand all dependencies started to download. I haven't had a settings.xml file before and I am not using any proxy. Hope it helps somebody.

然后 execmvn install和所有依赖项开始下载。我以前没有 settings.xml 文件,我没有使用任何代理。希望它可以帮助某人。

PD. I have jdk 1.7 and Maven 3.3.9

PD。我有 jdk 1.7 和 Maven 3.3.9

回答by Cyrano Dirac Djike Kemadjou

The simplest solution is to configure your JVM runtime arguments. On eclipse, you can do it as following :

最简单的解决方案是配置 JVM 运行时参数。在日食上,您可以按以下方式进行:

go to windows>preferences>java>installed JREs click on the Intalled JRE/JDK you are using for your project

转到 windows>preferences>java>installed JREs 单击您用于项目的 Intalled JRE/JDK

click on "edit" on le right, and add -Dhttps.protocols=TLSv1.2in the Default VM arguments Input field.

单击右侧的“编辑”,然后 -Dhttps.protocols=TLSv1.2在“默认 VM 参数输入”字段中添加。

see the screenshot :

看截图:

Screenshot

截屏

回答by sa3036

I had upgraded from Java 1.7 to Java 1.8 and got the same error. To resolve this error, I checked the mvn version using mvn -versionand found that JAVA_HOME was still using the Java 1.7. I changed the JAVA_HOME in the environment variable to point to Java 1.8 jre in JDK

我已经从 Java 1.7 升级到 Java 1.8 并遇到了同样的错误。为了解决这个错误,我检查了 mvn 版本mvn -version,发现 JAVA_HOME 仍在使用 Java 1.7。我将环境变量中的 JAVA_HOME 更改为指向 JDK 中的 Java 1.8 jre

Hope this helps someone.

希望这可以帮助某人。

回答by user4770620

It needs both : Configuring the JVM runtime arguments as well as having a settings.xml, after I did both it worked. Updating only the JVM runtime argument did not help.

它同时需要:配置 JVM 运行时参数以及具有 settings.xml,在我完成这两项工作之后。仅更新 JVM 运行时参数没有帮助。

回答by kartick shaw

The Package you are trying to install doesn't support TLS1.1and you might be by default using TLS 1.1 .Configure your Java runtime to enable TLS 1.2 by adding -Dhttps.protocols=TLSv1.2to your Maven Build command would solve the problem

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

For Example mvn clean install -Dhttps.protocols=TLSv1.2

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

回答by Yoshita Mahajan

I resolved this error in SpringToolSuitby adding settings.xmlfile in .m2folder which is located in Users folder of Cdrive and by updating Project by right click on pom.xml -> Maeven -> Update Project.

我通过在位于驱动器的用户文件夹中的文件夹中添加文件并通过右键单击更新项目解决了SpringToolSuit 中的此错误。settings.xml.m2Cpom.xml -> Maeven -> Update Project

Make sure you select Force update of snapshots/releases.

确保选择 Force update of snapshots/releases

回答by sohal

In my case the automatic update of maven dependencies were disabled in eclipse.
Solution:
Go to Windows->Preferences->Maven
and uncheck the check box

就我而言,在 Eclipse 中禁用了 Maven 依赖项的自动更新。
解决方案:
转到 Windows->Preferences->Maven
并取消选中复选框

"Do not automatically update dependencies from remote repositories"

不要自动更新远程存储库的依赖项

Then update the project
Right click on project->maven->update project

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