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


当前回答

如果您使用的是旧版本的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。

其他回答

我在Docker容器上使用干净的Maven/Java安装。

对我来说,我必须cd $M2_HOME/conf并编辑settings.xml文件。在<mirrors>…</mirrors>中添加以下块

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

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

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的变化

错误:

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

如果您使用的是旧版本的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。

我目前的环境不支持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>