Summary
I have a jekins installation on my infrastructure. I found that recently my maven jobs are failing with an exception saying that they couldn’nt pull dependencies. Here is how I solved it.
TL;DR
The quick answer is that I didn’t read the warning from maven team saying that HTTPS is now required.
As of January 15, 2020 I am receiving the following responses upon making requests to The Central Repository:
Requests to http://repo1.maven.org/maven2/ return a 501 HTTPS Required status and a body:
501 HTTPS Required. Use https://repo1.maven.org/maven2/ More information at https://links.sonatype.com/central/501-https-required
Requests to http://repo.maven.apache.org/maven2/ return a 501 HTTPS Required status and a body:
501 HTTPS Required. Use https://repo.maven.apache.org/maven2/ More information at https://links.sonatype.com/central/501-https-required
I should have read that notice :p
My configuration and the error I was having, in details
I am using maven 3.6.0 on Ubuntu 18.04.
Here is the error I was getting.
[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 Jenkins to 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]
The solution
To solve this problem, I did some replacements of the maven urls in my configuration.
Replace http://repo1.maven.org/maven2 with https://repo1.maven.org/maven2 (notice the https)
Replace http://repo.maven.apache.org/maven2 with https://repo.maven.apache.org/maven2
In case you cannot use https
In case you cannot use the secure connection https, there is a dedicated insecure endpoint you can use :
http://insecure.repo1.maven.org/maven2
Final thoughs
I hope this article helped solving your issue on Maven dependencies are failing with a 501 error.