最近,在Jenkins中运行的Maven构建作业失败,出现以下异常,表示它们无法从Maven Central提取依赖项,应该使用HTTPS。我不知道如何将请求从HTTP更改为HTTPS。有人能指导我一下这件事吗?
[ERROR] Unresolveable build extension:
Plugin org.apache.maven.wagon:wagon-ssh:2.1 or one of its dependencies could not be resolved:
Failed to collect dependencies for org.apache.maven.wagon:wagon-ssh:jar:2.1 ():
Failed to read artifact descriptor for org.apache.maven.wagon:wagon-ssh:jar:2.1:
Could not transfer artifact org.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 Jenkins to finish collecting data[ERROR]
Plugin org.apache.maven.plugins:maven-clean-plugin:2.4.1 or one of its dependencies could not be resolved:
Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.4.1:
Could not transfer artifact org.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]
尝试在任何浏览器中点击下面的URL。它会返回501
http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom
请尝试https。它会下载一个pom.xml文件:
https://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom
请在settings .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>
所观察到的错误的原因在中央501 HTTPS要求中有解释
自2020年1月15日起,中央存储库不再支持
在纯HTTP上的不安全通信,并要求所有请求
通过HTTPS加密到存储库。
看起来Maven的最新版本(在3.6.0和3.6.1中尝试过)默认情况下已经使用了HTTPS URL。
以下是主要存储库转换的日期:
你的Java构建可能会在1月13日开始崩溃(如果你还没有切换到HTTPS)
更新:似乎从maven 3.2.3 maven中心是通过HTTPS访问的
参见https://stackoverflow.com/a/25411658/5820670
Maven变更日志
(http://maven.apache.org/docs/3.2.3/release-notes.html)
对于所有的公司程序员来说,理想情况下,
如果您得到这个错误,这意味着您的代码库仍然是由开源社区构建的。您需要使用内部公司的Maven存储库管理器来超越“中央”存储库。
您可以转到settings.xml并将中央存储库URL从http://重写为https://
<M2_HOME>/conf/settings.xml
找到镜像部分并添加以下条目:
<mirror>
<id>other-mirror</id>
<name>Other Mirror Repository</name>
<url>https://other-mirror.repo.other-company.com/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
在URL部分,如果您使用http://repo1.maven.org/maven2/或http://repo.maven.apache.org/maven2/那么
将http://repo1.maven.org/maven2/替换为https://repo1.maven.org/maven2/
将http://repo.maven.apache.org/maven2/替换为https://repo.maven.apache.org/maven2/
理想情况下,您需要在这里使用您公司的源代码控制管理/存储库URL。因为这将阻止与开源Maven存储库社区的任何联系。
正如在其他回答中提到的,从2020年1月15日起,中央Maven存储库不支持纯HTTP上的不安全通信。
我也有同样的问题,但我用的是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://maven URLs. 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
我意识到这更适合我的设置。但是如果不执行上述所有步骤,我仍然会继续得到这个错误消息
返回代码是:501,ReasonPhrase:HTTPS Required
Maven正在转向HTTPS并禁用HTTP访问
简而言之,从2020年1月15日起,Maven中央存储库不再支持HTTP连接(其他存储库也在这么做)。因此,您将指示您的Maven/Gradle设置使用HTTPS URL。
解决方案:
您可以从以下三种方法中选择一种。
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
Gradle:
只替换HTTPS版本的URL。
repositories {
maven { url "https://repo.maven.apache.org/maven2" }
}
我也面临着同样的问题。我尝试了两种解决方案,对我来说都很有效。
更新Maven版本存储库(Maven版本>= 3.2.3)
限制当前Maven版本使用HTTPS链接。
更新Maven版本存储库:
下载包含默认https地址的Apache Maven二进制文件(Apache Maven 3.6.3二进制文件)。在NetBeans菜单栏的工具(Java Maven对话框视图)中打开选项对话框窗口。并在Maven Home List Box (Maven Home List Box View)中选择browse选项。添加新下载的Apache Maven版本(Updated Maven Home List Box View)后,项目构建并成功运行。
限制当前Maven版本使用HTTPS链接:
在项目的pom.xml中包含以下代码。
<project>
...
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<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>
</project>
正如在其他回答中所述,现在向Maven Central发出请求需要https,而旧版本的Maven使用http。
如果你不想/不能升级到Maven 3.2.3+,你可以通过添加以下代码到你的MAVEN_HOME\conf\settings.xml到<profiles>部分来解决:
<profile>
<id>maven-https</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
这将始终是一个活动设置,除非您在需要时在POM中禁用/覆盖它。
使用Ubuntu 16.04, java 1.8.0_201。
我卸载了旧的maven,安装了maven 3.6.3,
仍然得到了Maven依赖失败的501错误。
意识到这可能是与要求https相关的信任库/密钥库问题。
发现现在可以使用jvm配置-Djavax选项。配置文件,请参见:https://maven.apache.org/configure.html。
因为我也在使用Tomcat,所以我从Tomcat (setenv.sh)中将密钥库和信任库配置复制到我的jvm中。配置,然后它工作!
还有一个选项可以在“export MAVEN_OPTS”中传递这个配置(当使用mvn generate时),但尽管这阻止了501错误,但它创建了另一个:它期望一个pom文件。
创建一个单独的jvm。配置文件工作完美,只是把它放在你的项目的根。
希望这能帮助到一些人,我花了一整天才弄明白!
分享这些,以防有人需要:
旧的Gradle配置(没有Gitlab, Docker部署,用于简单项目)
repositories {
google()
jcenter()
maven { url "http://dl.bintray.com/davideas/maven" }
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://jcenter.bintray.com' }
}
新配置:
repositories {
google()
jcenter()
maven { url "https://dl.bintray.com/davideas/maven" }
maven { url 'https://plugins.gradle.org/m2/' }
maven { url 'https://repo1.maven.org/maven2' }
maven { url 'https://jcenter.bintray.com' }
}
注意https。快乐编码:)
错误:
传输文件失败:http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom。
返回代码是:501,ReasonPhrase:HTTPS Required。
根本原因分析:
Maven中心期望客户端使用https,但客户端只发出普通的HTTP请求。
因此,请求下载名为“wagon-ssh-2.1”的软件包。Pom’失败了。
如何解决这个问题?
替换URL“http://repo.maven.apache.org/maven2”
与“https://repo.maven.apache.org/maven2”
在pom.xml文件或构建。项目的Gradle文件。
最初来自https://stackoverflow.com/a/59796324/32453,虽然这可能有用:
注意,你的父pom也可以(重新)定义存储库,如果它因为某种原因覆盖了central并指定了http,你就需要修复它(修复的地方:~/.m2/settings.xml)
还有父母。
如果你不能在父pom中修复它,你可以覆盖父pom的repo,就像这样,在你的子pom中(从3.6.3默认的超级pom中提取,似乎他们也从repo1中更改了名称):
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url> <!-- the https you've been looking for -->
<layout>default</layout>
<snapshots>
<enabled>false</enabled> <!-- or set to true if desired, default is false -->
</snapshots>
</repository>
</repositories>
如果您使用的是旧版本的Netbeans,则必须在maven中进行更改才能在http上使用https
打开C:\Program Files\ NetBeans8.0.2\java\maven\conf\settings.xml
并将下面的代码粘贴在镜像标签之间
<mirror>
<id>maven-mirror</id>
<name>Maven Mirror</name>
<url>https://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
它将强制maven使用https://repo.maven.apache.org/maven2 url。
我也犯过这个错误。我照上面默罕默德说的做了。但是,它只解决了spring-boot-dependencies的错误,并且spring-boot-dependencies有子依赖项。有21个错误。之前是2个错误。是这样的:
Non-resolvable import POM: Could not transfer artifact org.springframework.cloud:spring-cloud-dependencies:pom:Hoxton.SR3 from/to central
错误消息中还要求使用HTTPS。
我将maven版本从3.2.2更新到3.6.3,将java版本从8更新到11。现在,https要求的所有错误都消失了。
更新maven版本
从这里下载最新的maven: Download maven
解压缩并将其移动到/opt/maven/
设置路径export path =$ path:/opt/maven/bin
并且,还从PATH中删除旧的maven
下面的链接让我摆脱了麻烦,
https://support.sonatype.com/hc/en-us/articles/360041287334-Central-501-HTTPS-Required
您可以在maven、apache-maven/conf/settings.xml中进行更改。
或者,如果在pom.xml中指定,则在那里进行更改。
之前,
<repository>
<id>maven_central_repo</id>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
Now,
<repository>
<id>maven_central_repo</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
注意从http到https的变化