简体   繁体   English

Maven 出现构建失败,如何解决此错误

[英]Maven is giving build failure , How to resolve this error

I have read other answers major answers are regarding giving settings.xml a proxy settings.我已阅读其他答案,主要答案是关于给 settings.xml 代理设置。 But when I gave proxy setting, build was saying unknown tag for every tag.但是当我给出代理设置时,构建是说每个标签的未知标签。 and also my chrome browser is not using any proxy setting.而且我的 chrome 浏览器没有使用任何代理设置。 I am working on netbeans in ubuntu os.我正在 ubuntu 操作系统中研究 netbeans。

full error is:完整的错误是:

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

<?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>


As the error clearly says, It should be https://repo.maven.apache.org/maven2 instead of http.正如错误清楚地表明,它应该是https://repo.maven.apache.org/maven2而不是 Z80791B3AED70 Please add that plugin repository URL in your settings.xml.请在您的 settings.xml 中添加该插件存储库 URL。

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

Thus your settings.xml should look like:因此您的 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>

If you click on the URL( http://repo.maven.apache.org/maven2 ), it will tell you that, HTTPS is required. If you click on the URL( http://repo.maven.apache.org/maven2 ), it will tell you that, HTTPS is required.

Change the repository URL from settings.xml file (if you are using Eclipse, then, go to Preference -> Maven -> User Settings, you will find the location of the file). Change the repository URL from settings.xml file (if you are using Eclipse, then, go to Preference -> Maven -> User Settings, you will find the location of the file).

Add following content into it:在其中添加以下内容:

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

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

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