最近,在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的一个过时版本(3.0.3和3.1)。这些旧版本不再支持http存储库(如上所述)。升级到Maven 3.6对我来说是解决办法。

其他回答

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

我也犯过这个错误。我照上面默罕默德说的做了。但是,它只解决了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
}

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

最初来自https://stackoverflow.com/a/59796324/32453,虽然这可能有用:

注意,你的父pom也可以(重新)定义存储库,如果它因为某种原因覆盖了central并指定了http,你就需要修复它(修复的地方:~/.m2/settings.xml) 还有父母。

如果你不能在父pom中修复它,你可以覆盖父pom的repo,就像这样,在你的子pom中(从3.6.3默认的超级pom中提取,似乎他们也从repo1中更改了名称):

  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url> <!-- the https you've been looking for -->
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled> <!-- or set to true if desired, default is false -->
      </snapshots>
    </repository>
  </repositories>