If you are getting the following error when you are building your Java project using maven or gradleFailed to transfer file: http://repo.maven.apache.org/maven2/<some/dependency/artifact>.pom Return code is: 501 , ReasonPhrase:HTTPS Required.
And you are thinking what happened, I haven’t changed anything in my project, no new dependencies, or repositories. The answers is that, you haven’t changed anything.
Do not panic! Effective January 15, 2020, the Central Repository is not longer supporting communication over HTTP and it requires requests to the repository must be over HTTPS.
What Do I need to do ?
The solution is very easy, you just need to replace the urls to maven central repository (and maybe other main repositories) to https instead of http. That’s all!!!
Replace: http://repo1.maven.org/maven2/
To: https://repo1.maven.org/maven2/
Replace: http://repo.maven.apache.org/maven2/
To: https://repo.maven.apache.org/maven2/
In case, you have never defined the repositories url and you are using the default values, you just need to add the new repositories with https.
How to add new repositories ?
There are 2 options, you can do it in your project’s pom.xml
file or you can do it in settings.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>
For settings.xml
file, you will need to create a profile and add the above code into that profile. Remember to activate that profile.
I prefer the option of adding the repository into my pom.xml
in the project.
What about Gradle?
Since gradle also uses the Maven Central Repository, you will need to update the values in the repository:
repositories { maven { url "https://repo.maven.apache.org/maven2" } }
Other Repositories that will disable HTTP
These are some other repositories the are also moving to https.
Repository | URL | Date |
Spring (Pivotal) | http://repo.spring.io | January 15, 2020 |
Gradle | http://repo.gradle.org | January 15, 2020 |
JFrog Bintray | http://jcenter.bintray.com | January 13, 2020 |
References
- https://support.sonatype.com/hc/en-us/articles/360041287334-Central-501-HTTPS-Required
- https://blog.sonatype.com/central-repository-moving-to-https
- https://maven.apache.org/guides/mini/guide-multiple-repositories.html
- https://www.alphabot.com/security/blog/2020/java/Your-Java-builds-might-break-starting-January-13th.html
[…] Maven is moving to HTTPS and disabling HTTP access […]
[…] Maven is moving to HTTPS and disabling HTTP access […]
Thanks, nice tips + advice
You’re welcome!
Realmente útil el post. Gracias por tu ayuda!!!
De nada! para eso estamos…