简体   繁体   English

Maven:尽管 settings.xml 具有使用 HTTPS 配置的存储库,但仍无法检索插件描述符和对等未通过身份验证的错误

[英]Maven: Failed to retrieve plugin descriptor and peer not authenticated errors despite the settings.xml having repositories configured with HTTPS

I have Maven 3.0.5 with Java 8 setup (that's for particular project and stack versions won't be revised).我有带有Java 8设置的Maven 3.0.5 (这是针对特定项目的,不会修改堆栈版本)。

I'm aware of Apache 's new decision to force all the Maven repositories to only use HTTPS, otherwise Maven clients won't be able to speak to the repository servers.我知道Apache强制所有 Maven 存储库仅使用 HTTPS 的新决定,否则 Maven 客户端将无法与存储库服务器通话。

It seems like I have configured all necessary settings in ~/.m2/settings.xml but for some reason, when I any build phase (say mvn clean ), Maven defaults to HTTP and doesn't care about settings.xml - it still attempts to download references/dependencies with HTTP protocol.似乎我已经在~/.m2/settings.xml配置了所有必要的设置,但出于某种原因,当我在任何构建阶段(比如mvn clean )时,Maven 默认为HTTP并且不关心settings.xml - 它仍然尝试使用 HTTP 协议下载引用/依赖项。

Example of my settings.xml (For simplicity, I removed project specific things and left only problem-related stuff):我的settings.xml示例(为简单起见,我删除了项目特定的内容,只留下了与问题相关的内容):

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                    https://maven.apache.org/xsd/settings-1.0.0.xsd">
<repositories>
  <repository>
    <id>central</id>
    <url>https://repo1.maven.org/maven2/</url>
  </repository>

  <repository>
    <id>central</id>
    <url>https://repo.maven.apache.org/maven2/</url>
  </repository>
</repositories>

and here is what I'm getting when I do mvn archetype:generate , just to test the behaviour of Maven (the problem is persistent for any other command that tries to reach servers out):这是我在执行mvn archetype:generate ,只是为了测试 Maven 的行为(对于任何其他试图将服务器连接到服务器的命令来说,问题仍然存在):

[INFO] Scanning for projects... 

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.3/maven-install-plugin-2.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-install-plugin:2.3: Plugin org.apache.maven.plugins:maven-install-plugin:2.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-install-plugin:jar:2.3

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:2.7: Plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:2.7

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-site-plugin/3.0/maven-site-plugin-3.0.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-site-plugin:3.0: Plugin org.apache.maven.plugins:maven-site-plugin:3.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-site-plugin:jar:3.0

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-antrun-plugin/1.3/maven-antrun-plugin-1.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-antrun-plugin:1.3: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-antrun-plugin:jar:1.3

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5: Plugin org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-beta-5

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.1/maven-dependency-plugin-2.1.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-dependency-plugin:2.1: Plugin org.apache.maven.plugins:maven-dependency-plugin:2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-dependency-plugin:jar:2.1

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-release-plugin/2.0/maven-release-plugin-2.0.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:2.0: Plugin org.apache.maven.plugins:maven-release-plugin:2.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-release-plugin:jar:2.0

Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml

[WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.

[WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.

[WARNING] Failure to transfer org.apache.maven.plugins/maven-metadata.xml from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.

Original error: Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.

[WARNING] Failure to transfer org.codehaus.mojo/maven-metadata.xml from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.

Original error: Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.

What shall I do?我该怎么办? as you see, it still uses HTTP, and I, correspondingly, get HTTP 501.如您所见,它仍然使用 HTTP,相应地,我得到 HTTP 501。

In your case, it seems to be working for dependencies, but not for plugins.在您的情况下,它似乎适用于依赖项,但不适用于插件。 You need to define a <profile> that is activeByDefault and contains a <pluginRepositories/> section for both snapshot and releases.您需要定义一个<profile> ,它是activeByDefault并且包含一个<pluginRepositories/>部分用于快照和发布。

Maven has two types of repositories: Maven 有两种类型的存储库:

  • For dependencies对于依赖项

  • For plugins对于插件

The <mirrorOf> section only handles dependency repositories. <mirrorOf>部分仅处理依赖项存储库。

There were two problems:有两个问题:

Problem 1:问题1:
[WARNING] Failed to retrieve plugin descriptor for .. (whatever plugin name) warnings during almost any build phase, which says that (important>) the retrieval of plugin descriptors or its dependencies (which means plugins , and not the project dependencies !) is not going successful. [WARNING] Failed to retrieve plugin descriptor for .. (whatever plugin name)几乎在任何构建阶段都[WARNING] Failed to retrieve plugin descriptor for .. (whatever plugin name)警告,这表示(重要>)插件描述符或其依赖项的检索(这意味着插件,而不是项目依赖项!)不会成功。

Here, Maven attempts to communicate with the end-point machine (repository) via HTTP, despite the fact (!), that I have customized my configuration .m2\\settings.xml file and all the repository definition entries are with HTTPS, respectively, seems like Maven should be trying everything via HTTPS ..but no, it uses HTTP for plugins, and any HTTP communication with Maven repositories is forbidden since the 15th of January, 2020 .在这里,Maven 尝试通过 HTTP 与端点机器(存储库)通信,尽管事实上(!),我已经自定义了我的配置.m2\\settings.xml文件并且所有存储库定义条目都分别使用 HTTPS,似乎 Maven 应该通过 HTTPS 尝试一切……但不,它使用 HTTP 作为插件,并且自 2020 年 1 月 15 日起禁止与 Maven 存储库进行任何 HTTP 通信。

The way I resolved this is to define and configure <profiles/> and <pluginRepositories/> as @carlspring suggested , but I had to elaborate and expand that answer a bit.我解决这个问题的方法是按照@carlspring 的建议定义和配置<profiles/><pluginRepositories/> ,但我不得不详细阐述和扩展这个答案。

So, here is my ready working settings.xml example: (note, that just to be safe, I provided alternative repositories in both - profiles and repositories)所以,这是我准备好的settings.xml示例:(注意,为了安全起见,我在配置文件和存储库中都提供了替代存储库)

<settings
        xmlns="http://maven.apache.org/SETTINGS/1.0.0"                                                                                                                                     $    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
        https://maven.apache.org/xsd/settings-1.0.0.xsd">

    <profiles>
        <profile>
            <id>ssl-profile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>

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

        <repositories>
            <repository>
                <id>central1</id>
                <url>https://repo1.maven.org/maven2/</url>
            </repository>
            <repository>
                <id>central2</id>
                <url>https://repo.maven.apache.org/maven2/</url>
            </repository>
        </repositories>
    </profiles>
</settings>

After this was resolved, and finally Maven attempted to connect to all the repositories via HTTPS , I then had another,在解决这个问题之后,最后 Maven 尝试通过HTTPS连接到所有存储库,然后我有了另一个,

Problem 2:问题2:
peer not authenticated followed by Return code is: 501 , ReasonPhrase:HTTPS Required. peer not authenticated后跟Return code is: 501 , ReasonPhrase:HTTPS Required.

This was a bit tricky, but the way of solving this is to play with truststore cacerts file.这有点棘手,但解决这个问题的方法是使用 truststore cacerts文件。

First, check whether you have truststore file cacerts and whether it's empty.首先,检查您是否有信任库文件cacerts以及它是否为空。 it must NOT be empty and this is very important.不能为空,这非常重要。

It seems like, in the OpenJDK 11 and in some other builds for Windows/Linux systems, cacerts file is either missing or present, but empty;似乎在OpenJDK 11和 Windows/Linux 系统的其他一些版本中, cacerts文件要么丢失要么存在,但为空; however, according to my observation, it was present in Oracle JDK builds.但是,根据我的观察,它存在于Oracle JDK版本中。

  • On Windows builds, it should be under %JAVA_HOME%\\lib\\security\\ ;Windows版本中,它应该在%JAVA_HOME%\\lib\\security\\
  • On Linux builds, it may vary (depending on Linux distribution and your setup), but in my case, it was under /etc/ssl/certs (and I think that's Linux's certificates folder, not particularly Java's one).在 Linux 版本中,它可能会有所不同(取决于 Linux 发行版和您的设置),但就我而言,它位于/etc/ssl/certs (我认为这是 Linux 的证书文件夹,而不是 Java 的文件夹)。

If you see, that cacerts file is either absent or empty (simply check the file size, it should be larger than few bits), you can either:如果您看到该cacerts文件不存在或为空(只需检查文件大小,它应该大于几位),您可以:

  • Simply copy-paste existing cacerts file from some other JDK/JRE build;简单地从其他一些 JDK/JRE 版本复制粘贴现有的cacerts文件;
  • Generate a cacerts truststore file and add certificate(s) to it. 生成cacerts信任库文件并向其添加证书。 In this case, you will need to add as many certificates as you need, so, maybe it's easier to go with just a copy-paste variant.在这种情况下,您需要根据需要添加尽可能多的证书,因此,使用复制粘贴变体可能更容易。

I hope this helps.我希望这有帮助。

I would suggest to go the following path:我建议走以下路径:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

  <mirrors>
    <mirror>
      <id>central</id>
      <name>central</name>
      <url>https://repo1.maven.org/maven2/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>

</settings>

This will redirect all request via the above URL.这将通过上述 URL 重定向所有请求。 If you have a repository manager inside of your corporate environment it's better to use this one and let the repo manager handle the https stuff.如果您的公司环境中有一个存储库管理器,最好使用它并让存储库管理器处理 https 内容。

Also an upgrade of Maven to most recent version 3.6.3 and I supose you are not using the most recent versions of plugins which I strongly recommend to upgrade there had been a lot of improvements.还将 Maven 升级到最新版本 3.6.3,我假设您没有使用我强烈建议升级的最新版本插件,其中有很多改进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM