Requests to http://repo1.maven.org/maven2/ return a 501 HTTPS Required status and a body [duplicate]
Asked Answered
C

5

53

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

How do I satisfy this requirement so that I can regain access to Central?

I got this error in the console

    [INFO] Scanning for projects...
    [INFO] 
    [INFO] ----------------------------<  >----------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] Downloading from : http://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/3.12.0/mongo-java-driver-3.12.0.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  11.136 s
    [INFO] Finished at: 2020-01-16T15:27:53+05:30
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project demo: Could not resolve dependencies for project com.tcs:demo:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.mongodb:mongo-java-driver:jar:3.12.0: Failed to read artifact descriptor for org.mongodb:mongo-java-driver:jar:3.12.0: Could not transfer artifact org.mongodb:mongo-java-driver:pom:3.12.0 from/to central (http://repo1.maven.org/maven2/): Failed to transfer http://repo1.maven.org/maven2/org/mongodb/mongo-java-driver/3.12.0/mongo-java-driver-3.12.0.pom. Error code 501, HTTPS Required -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace ``of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

And using site plugin:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:2.2:site (default-site) on project my-proj: SiteToolException: The site descriptor cannot be resolved from the repository: ArtifactResolutionException: Unable to locate site descriptor: Could not transfer artifact org.x.y:name:xml:site_en:3.5.1.b550 from/to central (http://repo1.maven.org/maven2): Transfer failed for http://repo1.maven.org/maven2/org/x/y/3.5.1.b550/name-3.5.1.b550-site_en.xml 501 HTTPS Required

Cherisecherish answered 16/1, 2020 at 7:24 Comment(0)
C
61

Effective January 15, 2020, The Central Repository no longer supports insecure communication over plain HTTP and requires that all requests to the repository are encrypted over HTTPS.

If you're receiving this error, then you need to replace all URL references to Maven Central with their canonical HTTPS counterparts:

Replace http://repo1.maven.org/maven2/ with https://repo1.maven.org/maven2/

Replace http://repo.maven.apache.org/maven2/ with https://repo.maven.apache.org/maven2/

If for any reason your environment cannot support HTTPS, you have the option of using our dedicated insecure endpoint at http://insecure.repo1.maven.org/maven2/

For further context around the move to HTTPS, please see https://blog.sonatype.com/central-repository-moving-to-https.

Cherisecherish answered 16/1, 2020 at 7:25 Comment(4)
how do you make this change? From the other posts, I've tried their suggestions and it still doesn't work. I've modified settings.xml and added the repositories to my pom.Encrata
I changed 'http' to 'https' is my BuildConfig.groovy, but still 'grails clean' reports http error and maven points to 'http'.Bantustan
This is so aweful on mavens part. Suddenly maven stops to work their own settings.Masha
What's the difference between repo1.maven.org/maven2 and repo.maven.apache.org/maven2 ?Mellon
M
61

I fixed with the following steps but it uses http: 1) got to .m2 folder 2) create file settings.xml 3) copy paste below

<settings>
    <mirrors>
        <mirror>
          <id>centralhttps</id>
          <mirrorOf>central</mirrorOf>
          <name>Maven central https</name>
          <url>http://insecure.repo1.maven.org/maven2/</url>
        </mirror>
      </mirrors>
      </settings>
Melodic answered 27/1, 2020 at 18:8 Comment(3)
This is the simplest solution. Thanks Man.Brnaby
Thanks a bunch. This really helped.Fincher
Why not use HTTPS in the URL? Using https://repo1.maven.org/maven2/ also solves the issue.Haim
C
13

Beware that your parent pom can (re) define repositories as well, and if it has overridden central and specified http for whatever reason, you'll need to fix that (so places to fix: ~/.m2/settings.xml AND also parent poms).

If you can't fix it in parent pom, you can override parent pom's repo's, like this, in your child pom (extracted from the 3.6.3 default super pom, seems they changed the name from repo1 as well):

  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url> <!-- the https you've been looking for -->
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled> <!-- or set to false if desired, default is true https://mcmap.net/q/130209/-in-a-maven-repository-entry-in-the-pom-are-snapshots-enabled-by-default -->
      </snapshots>
    </repository>
  </repositories>
Coquillage answered 18/1, 2020 at 0:5 Comment(0)
R
12

Try to add the next statament in your pom.xml

<pluginRepositories>
<pluginRepository>
  <id>central</id>
  <name>Central Repository</name>
  <url>https://repo.maven.apache.org/maven2</url>
  <layout>default</layout>
  <snapshots>
    <enabled>false</enabled>
  </snapshots>
  <releases>
    <updatePolicy>never</updatePolicy>
  </releases>
</pluginRepository>
</pluginRepositories>

<repositories>
 <repository>
   <id>central</id>
   <name>Central Repository</name>
   <url>https://repo.maven.apache.org/maven2</url>
   <layout>default</layout>
   <snapshots>
      <enabled>false</enabled>
   </snapshots>
 </repository>
</repositories>

Also, you have to specified the repositories in: MAVEN\conf\settings.xml

<mirrors>
 <mirror>
   <id>other-mirror</id>
   <mirrorOf>central</mirrorOf>
   <name>Other Mirror Repository</name>
   <url>http://insecure.repo1.maven.org/maven2/</url>
 </mirror>
 <mirror>
  <id>internal-repository</id>
  <name>Maven Repository Manager running on https://repo1.maven.org/maven2</name>
  <url>https://repo1.maven.org/maven2</url>
  <mirrorOf>*</mirrorOf>
 </mirror>
</mirrors>
Rancher answered 23/1, 2020 at 20:50 Comment(0)
K
8

FYI for Gradle users just use,

repositories {
   maven {
      url = 'https://repo.maven.apache.org/maven2'
   }
} 
Kendakendal answered 28/1, 2020 at 0:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.