Java 对 http://repo1.maven.org/maven2/ 的请求返回 501 HTTPS 必需状态和正文
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/59764749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Requests to http://repo1.maven.org/maven2/ return a 501 HTTPS Required status and a body
提问by Giriraj
As of January 15, 2020 I am receiving the following responses upon making requests to The Central Repository:
截至 2020 年 1 月 15 日,我在向中央存储库提出请求时收到以下回复:
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?
如何满足此要求以便我可以重新访问 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.xml501 HTTPS Required
[错误] 无法在项目 my-proj 上执行目标 org.apache.maven.plugins:maven-site-plugin:2.2:site (default-site):SiteToolException:无法从存储库解析站点描述符:ArtifactResolutionException:Unable定位站点描述符:无法传输工件 org.xy: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.xml501 需要 HTTPS
回答by Giriraj
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.
自 2020 年 1 月 15 日起,中央存储库不再支持通过普通 HTTP 进行的不安全通信,并要求对存储库的所有请求都通过 HTTPS 进行加密。
If you're receiving this error, then you need to replace all URL references to Maven Central with their canonical HTTPS counterparts:
如果您收到此错误,则需要将所有对 Maven Central 的 URL 引用替换为其规范的 HTTPS 对应项:
Replace http://repo1.maven.org/maven2/with https://repo1.maven.org/maven2/
将http://repo1.maven.org/maven2/替换为https://repo1.maven.org/maven2/
Replace http://repo.maven.apache.org/maven2/with https://repo.maven.apache.org/maven2/
将http://repo.maven.apache.org/maven2/替换为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/
如果由于任何原因您的环境不支持 HTTPS,您可以选择在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.
有关转向 HTTPS 的更多背景信息,请参阅https://blog.sonatype.com/central-repository-moving-to-https。
回答by rogerdpack
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).
请注意,您的父 pom 也可以(重新)定义存储库,并且如果它出于某种原因覆盖了中央和指定的 http,则您需要修复它(因此需要修复:~/.m2/settings.xml 以及父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):
如果您无法在父 pom 中修复它,您可以覆盖父 pom 的 repo,就像这样,在您的子 pom 中(从 3.6.3 默认超级 pom 中提取,似乎他们也从 repo1 更改了名称):
<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 true if desired, default is false -->
</snapshots>
</repository>
</repositories>
回答by Carlos Ruiz de la Vega
Try to add the next statament in your pom.xml
尝试在 pom.xml 中添加下一个 statament
<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
此外,您必须在以下位置指定存储库: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>
回答by Abay Gabdullin
I fixed with the following steps but it uses http: 1) got to .m2 folder 2) create file settings.xml 3) copy paste below
我修复了以下步骤,但它使用 http:1) 到 .m2 文件夹 2) 创建文件 settings.xml 3) 在下面复制粘贴
<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>
回答by Panduka DeSilva
FYI for Gradle users just use,
仅供 Gradle 用户使用,
repositories {
maven {
url = 'https://repo.maven.apache.org/maven2'
}
}