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


当前回答

我也犯过这个错误。我照上面默罕默德说的做了。但是,它只解决了spring-boot-dependencies的错误,并且spring-boot-dependencies有子依赖项。有21个错误。之前是2个错误。是这样的:

Non-resolvable import POM: Could not transfer artifact org.springframework.cloud:spring-cloud-dependencies:pom:Hoxton.SR3 from/to central

错误消息中还要求使用HTTPS。

我将maven版本从3.2.2更新到3.6.3,将java版本从8更新到11。现在,https要求的所有错误都消失了。

更新maven版本

从这里下载最新的maven: Download maven 解压缩并将其移动到/opt/maven/ 设置路径export path =$ path:/opt/maven/bin 并且,还从PATH中删除旧的maven

其他回答

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

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

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

而不是

repositories {
jcenter ()
//others
}

用这个:

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

更新Maven的中央存储库,使用https而不是http。

<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>

所观察到的错误的原因在中央501 HTTPS要求中有解释

自2020年1月15日起,中央存储库不再支持 在纯HTTP上的不安全通信,并要求所有请求 通过HTTPS加密到存储库。

看起来Maven的最新版本(在3.6.0和3.6.1中尝试过)默认情况下已经使用了HTTPS URL。

以下是主要存储库转换的日期:

你的Java构建可能会在1月13日开始崩溃(如果你还没有切换到HTTPS)

更新:似乎从maven 3.2.3 maven中心是通过HTTPS访问的 参见https://stackoverflow.com/a/25411658/5820670

Maven变更日志 (http://maven.apache.org/docs/3.2.3/release-notes.html)

错误:

传输文件失败:http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom。

返回代码是:501,ReasonPhrase:HTTPS Required。

根本原因分析:

Maven中心期望客户端使用https,但客户端只发出普通的HTTP请求。

因此,请求下载名为“wagon-ssh-2.1”的软件包。Pom’失败了。

如何解决这个问题?

替换URL“http://repo.maven.apache.org/maven2”

与“https://repo.maven.apache.org/maven2”

在pom.xml文件或构建。项目的Gradle文件。

在pom.xml中添加以下存储库。

<project>
...
    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Plugin Repository</name>
            <url>https://repo1.maven.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
...
</project>