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


当前回答

尝试在任何浏览器中点击下面的URL。它会返回501

http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom

请尝试https。它会下载一个pom.xml文件:

https://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom

请在settings .xml文件中添加它(https://repo.maven.apache.org/maven2):

<repositories>
   <repository>
      <id>Central Maven repository</id>
      <name>Central Maven repository https</name>
      <url>https://repo.maven.apache.org/maven2</url>
   </repository>
</repositories>

其他回答

我也有同样的问题,但我用的是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

我也面临着同样的问题。我尝试了两种解决方案,对我来说都很有效。

更新Maven版本存储库(Maven版本>= 3.2.3) 限制当前Maven版本使用HTTPS链接。

更新Maven版本存储库:

下载包含默认https地址的Apache Maven二进制文件(Apache Maven 3.6.3二进制文件)。在NetBeans菜单栏的工具(Java Maven对话框视图)中打开选项对话框窗口。并在Maven Home List Box (Maven Home List Box View)中选择browse选项。添加新下载的Apache Maven版本(Updated Maven Home List Box View)后,项目构建并成功运行。

限制当前Maven版本使用HTTPS链接:

在项目的pom.xml中包含以下代码。

<project>
      ...
    <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>
</project>

如果您使用的是旧版本的Netbeans,则必须在maven中进行更改才能在http上使用https

打开C:\Program Files\ NetBeans8.0.2\java\maven\conf\settings.xml 并将下面的代码粘贴在镜像标签之间

<mirror>
<id>maven-mirror</id>
<name>Maven Mirror</name>
<url>https://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>

它将强制maven使用https://repo.maven.apache.org/maven2 url。

对我来说(公司编码器)还在settings.xml中添加了一个镜像存储库修复了这个问题。我还在docker容器中使用Maven。

<mirrors>
    <mirror>
        <id>https-mirror</id>
        <name>Https Mirror Repository</name>
        <url>https://repo1.maven.org/maven2</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

正如在其他回答中所述,现在向Maven Central发出请求需要https,而旧版本的Maven使用http。

如果你不想/不能升级到Maven 3.2.3+,你可以通过添加以下代码到你的MAVEN_HOME\conf\settings.xml到<profiles>部分来解决:

<profile>
    <id>maven-https</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories> 
</profile>

这将始终是一个活动设置,除非您在需要时在POM中禁用/覆盖它。