最近,在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存储库管理器来超越“中央”存储库。
您可以转到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