最近,在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]
下面的链接让我摆脱了麻烦,
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的变化
所观察到的错误的原因在中央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)
尝试在任何浏览器中点击下面的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>
如果您使用的是旧版本的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。
正如在其他回答中所述,现在向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中禁用/覆盖它。