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


当前回答

Maven正在转向HTTPS并禁用HTTP访问

简而言之,从2020年1月15日起,Maven中央存储库不再支持HTTP连接(其他存储库也在这么做)。因此,您将指示您的Maven/Gradle设置使用HTTPS URL。

解决方案:

您可以从以下三种方法中选择一种。

Add a repository in your project´s pom.xml file <project> ... <repositories> <repository> <id>central maven repo</id> <name>central maven repo https</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </project> Add the repository into a profile in the settings.xml file. <profile> <id>my profile</id> <repositories> <repository> <id>central maven repo</id> <name>central maven repo https</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </profile> Update you maven version to a new one that uses https values as default. The lastest one at this moment 3.6.3 Download here

Gradle:

只替换HTTPS版本的URL。

repositories {
   maven { url "https://repo.maven.apache.org/maven2" }
}

其他回答

Maven正在转向HTTPS并禁用HTTP访问

简而言之,从2020年1月15日起,Maven中央存储库不再支持HTTP连接(其他存储库也在这么做)。因此,您将指示您的Maven/Gradle设置使用HTTPS URL。

解决方案:

您可以从以下三种方法中选择一种。

Add a repository in your project´s pom.xml file <project> ... <repositories> <repository> <id>central maven repo</id> <name>central maven repo https</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </project> Add the repository into a profile in the settings.xml file. <profile> <id>my profile</id> <repositories> <repository> <id>central maven repo</id> <name>central maven repo https</name> <url>https://repo.maven.apache.org/maven2</url> </repository> </repositories> </profile> Update you maven version to a new one that uses https values as default. The lastest one at this moment 3.6.3 Download here

Gradle:

只替换HTTPS版本的URL。

repositories {
   maven { url "https://repo.maven.apache.org/maven2" }
}

尝试在任何浏览器中点击下面的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>

我下载了最新的eclipse,并从这里使用https://www.eclipse.org/downloads/packages/release/,这解决了我的问题。

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

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