0

I have read other answers major answers are regarding giving settings.xml a proxy settings. 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. I am working on netbeans in ubuntu os.

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

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


2 Answers2

1

As the error clearly says, It should be https://repo.maven.apache.org/maven2 instead of http. Please add that plugin repository URL in your settings.xml.

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

Thus your settings.xml should look like:

<?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>
Abhinaba Chakraborty
  • 3,488
  • 2
  • 16
  • 37
  • @aakash Can you please try this out and let us know if it helps – Abhinaba Chakraborty Jul 13 '20 at 05:56
  • I have put my setting.xml here , can you plz point where to put this url – aakash sharma Jul 13 '20 at 06:02
  • Looks like you dont have pluginRepositories defined in your settings xml. Please add this block within your profile. – Abhinaba Chakraborty Jul 13 '20 at 06:38
  • Thanks this is working, but last time 1 yr ago when I used maven I never used settings.xml even and my web app was working fine , why so? do you have idea – aakash sharma Jul 13 '20 at 06:50
  • which IDE you are using? – Abhinaba Chakraborty Jul 13 '20 at 06:51
  • it is netbeans in ubuntu , last time it was eclipse + windows – aakash sharma Jul 13 '20 at 06:52
  • 1
    @aakashsharma this is because until about March 2020 (four month ago) the repo.maven.apache.org was reachable over insecure HTTP connections. That was a security risk (somebody could intercept your traffic to repo.maven.apache.org and send you malicious code for your dependencies) – Thomas Kläger Jul 13 '20 at 06:53
  • So there is the catch..every IDE has it's own locally defined configuration for build tools like Maven/Gradle. It must be defined as default in your eclipse – Abhinaba Chakraborty Jul 13 '20 at 06:53
  • @ThomasKläger I didnt know about this.. I have been using Intellij for past couple of years and the default is HTTPS – Abhinaba Chakraborty Jul 13 '20 at 06:55
  • 1
    @AbhinabaChakraborty if you regularly update your toolset (Maven, Intellij) then the change from HTTP to HTTPS occured due to these updates (if you did not specify a settings.xml with HTTP URLs) - according to https://stackoverflow.com/questions/59763531/maven-dependencies-are-failing-with-a-501-error upgrading maven to at least 3.2.3 solved the problem for most users (except users on ubuntu it seems...) – Thomas Kläger Jul 13 '20 at 11:36
0

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

Add following content into it:

 <repository> 
       <id>central</id>
       <url>https://repo.maven.apache.org/maven2/</url>
   </repository>
NiTiN
  • 81
  • 1
  • 9