Java Maven 依赖项失败并出现 501 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/59763531/
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
Maven dependencies are failing with a 501 error
提问by Arunan Sugunakumar
Recently Mavenbuild jobs running in Jenkinsare failing with the below exception saying that they couldn't pull dependencies from Maven Centraland should use HTTPS. I'm not sure how to change the requests from HTTPto HTTPS. Could someone guide me on this matter?
最近在Jenkins中运行的Maven构建作业失败,出现以下异常,表示它们无法从Maven Central 中提取依赖项,应使用HTTPS。我不确定如何将请求从HTTP更改为HTTPS。有人可以指导我解决这个问题吗?
[ERROR] Unresolveable build extension:
Pluginorg.apache.maven.wagon:wagon-ssh:2.1
or one of its dependencies could not be resolved:
Failed to collect dependencies fororg.apache.maven.wagon:wagon-ssh:jar:2.1 ()
:
Failed to read artifact descriptor fororg.apache.maven.wagon:wagon-ssh:jar:2.1
:
Could not transfer artifactorg.apache.maven.wagon:wagon-ssh:pom:2.1
from/to central (http://repo.maven.apache.org/maven2):
Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom.
Return code is:501, ReasonPhrase:HTTPS Required. -> [Help 2]
Waiting for Jenkinsto finish collecting
data[ERROR]
Pluginorg.apache.maven.plugins:maven-clean-plugin:2.4.1
or one of its dependencies could not be resolved:
Failed to read artifact descriptor fororg.apache.maven.plugins:maven-clean-plugin:jar:2.4.1
:
Could not transfer artifactorg.apache.maven.plugins:maven-clean-plugin:pom:2.4.1
from/to central (http://repo.maven.apache.org/maven2):
Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom.
Return code is:501 , ReasonPhrase:HTTPS Required. -> [Help 1]
[错误] 无法解析的构建扩展:
插件org.apache.maven.wagon:wagon-ssh:2.1
或其依赖项之一无法解析:
无法收集依赖项org.apache.maven.wagon:wagon-ssh:jar:2.1 ()
:
无法读取工件描述符org.apache.maven.wagon:wagon-ssh:jar:2.1
:
无法org.apache.maven.wagon:wagon-ssh:pom:2.1
从/向中央(http://repo.maven.apache. org/maven2):
无法传输文件:http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom。
返回代码为:501, ReasonPhrase:HTTPS Required. -> [Help 2]
等待Jenkins完成收集
data[ERROR]
插件org.apache.maven.plugins:maven-clean-plugin:2.4.1
或其依赖项之一无法解决:
无法读取工件描述符org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1
:
无法org.apache.maven.plugins:maven-clean-plugin:pom:2.4.1
从/向中央传输工件(http://repo.maven.apache.org/maven2):
无法传输文件:http: //repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.4.1/maven-clean-plugin-2.4.1.pom。
返回代码为:501 , ReasonPhrase:HTTPS Required. -> [Help 1]
采纳答案by farasath
The reason for the observed error is explained in Central 501 HTTPS Required
Central 501 HTTPS Required 中解释了观察到的错误的原因
Effective January 15, 2020, The Central Repository no longer supports insecure communication over plain HTTP and requires that all requests to the repository are encrypted over HTTPS.
自 2020 年 1 月 15 日起,中央存储库不再支持通过普通 HTTP 进行的不安全通信,并要求对存储库的所有请求都通过 HTTPS 进行加密。
It looks like latest versions of Maven (tried with 3.6.0, 3.6.1) are already using the HTTPS URL by default.
看起来最新版本的 Maven(在 3.6.0、3.6.1 中尝试过)默认已经在使用 HTTPS URL。
Here are the dates when the major repositories will switch:
以下是主要存储库切换的日期:
从 1 月 13 日开始,您的 Java 构建可能会中断(如果您尚未将 repo 访问权限切换到 HTTPS)
Update: Seems like from maven 3.2.3 maven central is accessed via HTTPS See https://stackoverflow.com/a/25411658/5820670
更新:似乎从 maven 3.2.3 maven central 通过 HTTPS 访问见https://stackoverflow.com/a/25411658/5820670
Maven Change log (http://maven.apache.org/docs/3.2.3/release-notes.html)
Maven 更改日志 ( http://maven.apache.org/docs/3.2.3/release-notes.html)
回答by Sarjit
Try to hit the below URL in any browser. It will return 501
尝试在任何浏览器中点击以下 URL。它将返回 501
http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom
http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom
Please try with https. It will download a pom.xml file:
请尝试使用 https。它将下载一个 pom.xml 文件:
https://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom
https://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom
Please add it (https://repo.maven.apache.org/maven2) in the setting.xml file:
请在 setting.xml 文件中添加它(https://repo.maven.apache.org/maven2):
<repositories>
<repository>
<id>Central Maven repository</id>
<name>Central Maven repository https</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
回答by Ashwani
Effective January 15, 2020, The Central Repository no longer supports insecure communication over plain HTTP and requires that all requests to the repository are encrypted over HTTPS.
If you're receiving this error, then you need to replace all URL references to Maven Central with their canonical HTTPS counterparts.
自 2020 年 1 月 15 日起,中央存储库不再支持通过普通 HTTP 进行的不安全通信,并要求对存储库的所有请求都通过HTTPS加密。
如果您收到此错误,则需要将所有对 Maven Central 的 URL 引用替换为其规范的 HTTPS 对应项。
(source)
(来源)
We have made the following changes in my project's build.gradle:
我们在我的项目的 build.gradle 中进行了以下更改:
Old:
老的:
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
New:
新的:
repositories {
maven { url "https://repo.maven.apache.org/maven2" }
}
回答by Bhavik Shah
For all the corporate coders, ideally, if you get this error, it means that your code base is still being built from open-source community. You need to over ride the "central" repository with your in house company Maven repository manager.
对于所有企业编码人员,理想情况下,如果出现此错误,则意味着您的代码库仍在从开源社区构建。您需要使用内部公司 Maven 存储库管理器来管理“中央”存储库。
You can go to your settings.xml and override your central repository URL from http:// to https://
您可以转到 settings.xml 并将中央存储库 URL 从 http:// 覆盖到 https://
<M2_HOME>/conf/settings.xml
Find the mirrorssections and add the following entry:
找到镜像部分并添加以下条目:
<mirror>
<id>other-mirror</id>
<name>Other Mirror Repository</name>
<url>https://other-mirror.repo.other-company.com/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
In the URL section, if you were using either http://repo1.maven.org/maven2/or http://repo.maven.apache.org/maven2/then
在 URL 部分,如果您使用的是http://repo1.maven.org/maven2/或http://repo.maven.apache.org/maven2/那么
Replace http://repo1.maven.org/maven2/with https://repo1.maven.org/maven2/
将http://repo1.maven.org/maven2/替换为https://repo1.maven.org/maven2/
Replace http://repo.maven.apache.org/maven2/with https://repo.maven.apache.org/maven2/
将http://repo.maven.apache.org/maven2/替换为https://repo.maven.apache.org/maven2/
You need to ideally use your company source control management/repository URL over here. As this will block any contact with open source Maven repository community.
理想情况下,您需要在此处使用您公司的源代码控制管理/存储库 URL。因为这将阻止与开源 Maven 存储库社区的任何联系。
As mentioned in other answers, effective from 15 January 2020, the central Maven repository doesn't support insecure communication over plain HTTP.
如其他答案中所述,自 2020 年 1 月 15 日起,中央 Maven 存储库不支持通过普通 HTTP 进行的不安全通信。
回答by Sumeet Vishwas
Update the central repository of Maven and use httpsinstead of http.
更新 Maven 的中央存储库并使用https而不是http。
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
回答by JC Lombard
I was using an outdated version of Maven (3.0.3 and 3.1). These older versions no longer supports http repositories (as mentioned above). Upgrading to Maven 3.6 was the fix for me.
我使用的是过时版本的 Maven(3.0.3 和 3.1)。这些旧版本不再支持 http 存储库(如上所述)。升级到 Maven 3.6 对我来说是解决方案。
回答by Sathesh
Add the following repository in pom.xml.
在pom.xml 中添加以下存储库。
<project>
...
<repositories>
<repository>
<id>central</id>
<name>Maven Plugin Repository</name>
<url>https://repo1.maven.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
...
</project>
回答by mehulmpt
I was using a clean install of Maven/Java on a Docker container.
我在 Docker 容器上使用全新安装的 Maven/Java。
For me, I had to cd $M2_HOME/conf
and edit the settings.xml
file there. Add the following block inside <mirrors>...</mirrors>
对我来说,我必须cd $M2_HOME/conf
在settings.xml
那里编辑文件。在里面添加以下块<mirrors>...</mirrors>
<mirror>
<id>central-secure</id>
<url>https://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
回答by CAM_344
I have the same issue, but I use GitLabinstead of Jenkins. The steps I had to do to get over the issue:
我有同样的问题,但我使用GitLab而不是 Jenkins。我必须采取的步骤来解决这个问题:
- My project is in GitLab so it uses the .yml file which points to a Docker image I have to do continuous integration, and the image it uses has the http://mavenURLs. So I changed that to https://maven.
- That same Dockerfile image had an older version of Maven 3.0.1 that gave me issues just overnight. I updated the Dockerfile to get the latest version 3.6.3
- I then deployed that image to my online repository, and updated my Maven project ymlfile to use that new image.
- And lastly, I updated my main projects POM file to reference https://maven...instead of http://maven
- 我的项目在 GitLab 中,因此它使用 .yml 文件,该文件指向我必须进行持续集成的 Docker 映像,并且它使用的映像具有http://mavenURL。所以我把它改成了https://maven。
- 同一个 Dockerfile 映像有一个旧版本的 Maven 3.0.1,一夜之间就给我出了问题。我更新了 Dockerfile 以获得最新版本 3.6.3
- 然后我将该映像部署到我的在线存储库,并更新了我的 Maven 项目 ymlfile 以使用该新映像。
- 最后,我更新了我的主要项目 POM 文件以引用https://maven...而不是http://maven
I realize that is more specific to my setup. But without doing all of the steps above I would still continue to get this error message
Return code is: 501 , ReasonPhrase:HTTPS Required
我意识到这更特定于我的设置。但是如果不执行上述所有步骤,我仍然会继续收到此错误消息
Return code is: 501 , ReasonPhrase:HTTPS Required
回答by Adam M. Gamboa G.
Maven is moving to HTTPS and disabling HTTP access
Short story, from January 15, 2020, Maven Central repository is not longer supporting HTTP connections (other repositories are doing the same). Therefore, you will indicate your Maven/Gradle settings to use an HTTPS URL.
简而言之,从 2020 年 1 月 15 日起,Maven 中央存储库不再支持 HTTP 连接(其他存储库也在做同样的事情)。因此,您将指示您的 Maven/Gradle 设置使用 HTTPS URL。
Solution:
解决方案:
You can choose one of the following three approaches.
您可以选择以下三种方法之一。
Add a repository in your project′s
pom.xml
file<project> ... <repositories> <repository> <id>central maven repo</id> <name>central maven repo https</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </project>
Add the repository into a profile in the
settings.xml
file.<profile> <id>my profile</id> <repositories> <repository> <id>central maven repo</id> <name>central maven repo https</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </profile>
- Update you maven version to a new one that uses https values as default. The lastest one at this moment 3.6.3 Download here
在您的项目
pom.xml
文件中添加一个存储库<project> ... <repositories> <repository> <id>central maven repo</id> <name>central maven repo https</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </project>
将存储库添加到文件中的配置
settings.xml
文件中。<profile> <id>my profile</id> <repositories> <repository> <id>central maven repo</id> <name>central maven repo https</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </profile>
- 将您的 Maven 版本更新为使用 https 值作为默认值的新版本。此刻最新的 3.6.3点此下载
For Gradle:
对于摇篮:
Only replace the URL for the HTTPS version.
仅替换 HTTPS 版本的 URL。
repositories {
maven { url "https://repo.maven.apache.org/maven2" }
}