【问题标题】:Maven is giving build failure , How to resolve this errorMaven 出现构建失败,如何解决此错误
【发布时间】:2020-11-02 07:04:39
【问题描述】:

我已阅读其他答案,主要答案是关于为 settings.xml 提供代理设置。但是当我给出代理设置时,构建是说每个标签的标签都是未知的。 而且我的 chrome 浏览器没有使用任何代理设置。 我正在 ubuntu 操作系统中开发 netbeans。

完全错误是:

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]

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>mavenproject1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

settings.xml

<?xml version="1.0" encoding="UTF-8"?>

<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <repositories>
                <repository> 
                    <id>central</id>
                    <url>https://repo.maven.apache.org/maven2/</url>
                </repository>
            </repositories>
        </profile>
    </profiles>
    
    
</settings>


【问题讨论】:

  • 您应该提供一个存储库 url 来解决依赖关系。你能显示你的pom.xml
  • @papaya 请检查 pom.xml

标签: java web-applications maven-2


【解决方案1】:

正如错误清楚地表明,它应该是https://repo.maven.apache.org/maven2 而不是http。 请在您的 settings.xml 中添加该插件存储库 URL。

      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>https://repo.maven.apache.org/maven2/</url>
        </pluginRepository>
      </pluginRepositories>

因此您的 settings.xml 应该如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>profile-1</id>
            <activation>
               <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>
                <repository> 
                    <id>central</id>
                    <url>https://repo.maven.apache.org/maven2/</url>
                </repository>
            </repositories>
            <pluginRepositories>
              <pluginRepository>
                <id>central</id>
                <url>https://repo.maven.apache.org/maven2/</url>
              </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    
    
</settings>

【讨论】:

  • @aakash 你能试试这个,如果有帮助请告诉我们
  • 我已经把我的setting.xml放在这里了,你能指出把这个网址放在哪里
  • 看起来您的设置 xml 中没有定义 pluginRepositories。请在您的个人资料中添加此块。
  • @aakashsharma 这是因为直到大约 2020 年 3 月(四个月前),才能通过不安全的 HTTP 连接访问 repo.maven.apache.org。这是一个安全风险(有人可能会拦截你到 repo.maven.apache.org 的流量并向你发送依赖项的恶意代码)
  • @AbhinabaChakraborty 如果您定期更新您的工具集(Maven、Intellij),那么由于这些更新(如果您没有指定带有 HTTP URL 的 settings.xml),从 HTTP 到 HTTPS 的变化发生了 - 根据stackoverflow.com/questions/59763531/… 将 maven 升级到至少 3.2.3 解决了大多数用户的问题(似乎除了 ubuntu 上的用户......)
【解决方案2】:

如果你点击 URL(http://repo.maven.apache.org/maven2),它会告诉你,需要 HTTPS。

从 settings.xml 文件更改存储库 URL(如果您使用的是 Eclipse,则转到 Preference -> Maven -> User Settings,您将找到该文件的位置)。

添加以下内容:

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

【讨论】:

  • 我已经更新了setting.xml并在这里更新了,还是不行,请检查是否正确
猜你喜欢
  • 2021-11-27
  • 1970-01-01
  • 2014-02-06
  • 2019-07-10
  • 2019-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多