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


当前回答

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

其他回答

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

我也有同样的问题,但我用的是GitLab而不是Jenkins。我必须采取的步骤来克服这个问题:

My project is in GitLab so it uses the .yml file which points to a Docker image I have to do continuous integration, and the image it uses has the http://maven URLs. So I changed that to https://maven. That same Dockerfile image had an older version of Maven 3.0.1 that gave me issues just overnight. I updated the Dockerfile to get the latest version 3.6.3 I then deployed that image to my online repository, and updated my Maven project ymlfile to use that new image. And lastly, I updated my main projects POM file to reference https://maven... instead of http://maven

我意识到这更适合我的设置。但是如果不执行上述所有步骤,我仍然会继续得到这个错误消息 返回代码是:501,ReasonPhrase:HTTPS Required

错误:

传输文件失败: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文件。

我目前的环境不支持HTTPS,所以添加不安全版本的repo解决了我的问题:http://insecure.repo1.maven.org按照Sonatype

    <repositories>
       <repository>
          <id>Central Maven repository</id>
          <name>Central Maven repository insecure</name>
          <url>http://insecure.repo1.maven.org</url>
       </repository>
    </repositories>

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

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

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