最近,在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]


当前回答

下面的链接让我摆脱了麻烦,

https://support.sonatype.com/hc/en-us/articles/360041287334-Central-501-HTTPS-Required

您可以在maven、apache-maven/conf/settings.xml中进行更改。 或者,如果在pom.xml中指定,则在那里进行更改。

之前,

<repository>
            <id>maven_central_repo</id>
            <url>http://repo.maven.apache.org/maven2</url>
</repository>

Now,

<repository>
            <id>maven_central_repo</id>
            <url>https://repo.maven.apache.org/maven2</url>
</repository>

注意从http到https的变化

其他回答

将此添加到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>

我下载了最新的netbeans 12.2版本,问题得到了解决。

同样的问题也发生在jcenter上。

自2020年1月13日起,Jcenter仅支持HTTPS协议。

使用相同方法获得依赖项的项目将开始面临问题。为了快速修复,请在build.gradle中执行以下操作

而不是

repositories {
jcenter ()
//others
}

用这个:

repositories {
jcenter { url "http://jcenter.bintray.com/"}
//others
}

我在最新版本(2020年8月)遇到了这个问题(在这台机器上很久没有使用Maven了),在阅读这些答案后,为什么它仍然是一个问题,我摸不着头脑。

原来我在我的主目录的.m2/文件夹里有一个旧的settings.xml,其中有一些多年前的自定义。

然而,即使删除了那个文件,我也无法解决这个问题。我最终删除了整个。m2文件夹。 我认为除了下载的资源,里面没有其他东西。也许仅仅删除repository/org/apache/maven/ prototype这样的文件夹就足够了。

对于所有的公司程序员来说,理想情况下, 如果您得到这个错误,这意味着您的代码库仍然是由开源社区构建的。您需要使用内部公司的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上的不安全通信。