最近,在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]
正如在其他回答中所述,现在向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中禁用/覆盖它。
错误:
传输文件失败: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文件。
尝试在任何浏览器中点击下面的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>