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


当前回答

自2020年1月15日起,中央存储库不再支持 在纯HTTP上的不安全通信,并要求所有请求 通过HTTPS加密到存储库。 如果收到此错误,则需要替换所有URL 对Maven Central的引用及其规范的HTTPS对等物。

(源)

我们在我的项目build.gradle中做了以下更改:

Old:

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

New:

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

其他回答

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

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

使用Ubuntu 16.04, java 1.8.0_201。

我卸载了旧的maven,安装了maven 3.6.3, 仍然得到了Maven依赖失败的501错误。

意识到这可能是与要求https相关的信任库/密钥库问题。 发现现在可以使用jvm配置-Djavax选项。配置文件,请参见:https://maven.apache.org/configure.html。

因为我也在使用Tomcat,所以我从Tomcat (setenv.sh)中将密钥库和信任库配置复制到我的jvm中。配置,然后它工作!

还有一个选项可以在“export MAVEN_OPTS”中传递这个配置(当使用mvn generate时),但尽管这阻止了501错误,但它创建了另一个:它期望一个pom文件。

创建一个单独的jvm。配置文件工作完美,只是把它放在你的项目的根。

希望这能帮助到一些人,我花了一整天才弄明白!

自2020年1月15日起,中央存储库不再支持 在纯HTTP上的不安全通信,并要求所有请求 通过HTTPS加密到存储库。 如果收到此错误,则需要替换所有URL 对Maven Central的引用及其规范的HTTPS对等物。

(源)

我们在我的项目build.gradle中做了以下更改:

Old:

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

New:

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

对我来说(公司编码器)还在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>