首页 > 解决方案 > 具有本地文件依赖项的 Maven 项目构建错误 501

问题描述

我有具有本地依赖项的 maven 项目,它无法编译,因为 maven 引入了这种“改进”:

自 2020 年 1 月 15 日起,中央存储库不再支持通过纯 HTTP 进行的不安全通信,并要求对存储库的所有请求都通过 HTTPS 进行加密。

这是我的 pom.xml:

...
<repositories>
    <repository>
        <id>in-project</id>
        <name>In Project Repo</name>
        <url>file://${project.basedir}/libs</url>
    </repository>
</repositories>
...

所以现在我收到以下编译错误:

无法解析项目的依赖项............:war:1.0:无法
收集[............:jar:1.0(编译)的依赖项,
javax:javaee-web-api: jar:7.0 (提供), .........:jar:1.0
(compile)]: 无法读取
.........:jar:1.0 的工件描述符: 无法传输工件
。 ........:pom:1.0 from/to central
( http://repo.maven.apache.org/maven2 ): 传输文件失败:
http://repo.maven.apache.org/maven2 /com/..../..../1.0/.....-1.0.pom
返回码为:501,ReasonPhrase:HTTPS 必需。-> [帮助 1]

如您所见,我正在使用本地 jar 文件,但这不再编译

有谁知道如何配置本地存储库以成功编译?

标签: javamavenlocal

解决方案


Maven 服务器不再支持 HTTP。您必须在本地 maven 配置文件中的主文件夹 yourname/.m2/settings.xml 中使用 HTTPS url 配置 maven 存储库。

这是您可以复制的示例:

<?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">
   <profiles>
      <profile>
         <id>artifactory</id>
         <repositories>
            <repository>
               <snapshots>
                  <enabled>false</enabled>
               </snapshots>
               <id>central</id>
               <name>libs-release</name>
               <url>https://repo1.maven.org/maven2/</url>
            </repository>
            <repository>
               <snapshots />
               <id>snapshots</id>
               <name>libs-snapshot</name>
               <url>https://repo1.maven.org/maven2/</url>
            </repository>
         </repositories>
         <pluginRepositories>
            <pluginRepository>
               <snapshots>
                  <enabled>false</enabled>
               </snapshots>
               <id>central</id>
               <name>plugins-release</name>
               <url>https://repo1.maven.org/maven2/</url>
            </pluginRepository>
            <pluginRepository>
               <snapshots />
               <id>snapshots</id>
               <name>plugins-snapshot</name>
               <url>https://repo1.maven.org/maven2/</url>
            </pluginRepository>
         </pluginRepositories>         
      </profile>
   </profiles>
   <activeProfiles>
      <activeProfile>artifactory</activeProfile>
   </activeProfiles>
</settings>

推荐阅读