Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven dependencies are failing with a 501 error

Recently Maven build jobs running in Jenkins are failing with the below exception saying that they couldn't pull dependencies from Maven Central and should use HTTPS. I'm not sure how to change the requests from HTTP to HTTPS. Could someone guide me on this matter?

[ERROR] Unresolveable build extension:
Plugin org.apache.maven.wagon:wagon-ssh:2.1 or one of its dependencies could not be resolved:
Failed to collect dependencies for org.apache.maven.wagon:wagon-ssh:jar:2.1 ():
Failed to read artifact descriptor for org.apache.maven.wagon:wagon-ssh:jar:2.1:
Could not transfer artifact org.apache.maven.wagon:wagon-ssh:pom:2.1 from/to central (http://repo.maven.apache.org/maven2):
Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/wagon/wagon-ssh/2.1/wagon-ssh-2.1.pom.
Return code is: 501, ReasonPhrase:HTTPS Required. -> [Help 2]

Waiting for Jenkins to finish collecting data[ERROR]
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]

like image 468
Arunan Sugunakumar Avatar asked Oct 19 '22 11:10

Arunan Sugunakumar


People also ask

What is the latest Maven version?

Apache Maven 3.8.6 is the latest release and recommended version for all users.

Why does my Maven project fail?

In your maven project, If the dependencies are placed not properly. This may result to create problems such as unused dependencies, duplicate dependencies, version conflicts…etc. These result execution failure of the project.

What is MVN dependency analyze command?

This command help to find out what are the used, declared, and undeclared dependencies in your project. This is a superb command for cleanup your pom. Let's check out how the mvn dependency:analyze command works for the above pom.xml. In the above project, I used only the dependency commons-lang3 in the code.

How to find unused dependencies of a project?

You can see the command lists the unused dependencies of the project (jasperreports) This command will go over your dependencyMangement and dependencies on the pom.xml and find out the duplicate dependencies used. It is beneficial to find out duplicate dependencies of large projects such as the multi-module projects.

How many commands resolve dependency related problems?

Let's find out more about these commands as part of this article. Here is the set of 8 important commands that resolves dependency related problems.


2 Answers

The reason for the observed error is explained in Central 501 HTTPS Required

Effective January 15, 2020, The Central Repository no longer supports insecure communication over plain HTTP and requires that all requests to the repository are encrypted over HTTPS.

It looks like latest versions of Maven (tried with 3.6.0, 3.6.1) are already using the HTTPS URL by default.

Here are the dates when the major repositories will switch:

Your Java builds might break starting January 13th (if you haven't yet switched repo access to HTTPS)

Update: Seems like from maven 3.2.3 maven central is accessed via HTTPS See https://stackoverflow.com/a/25411658/5820670

Maven Change log (http://maven.apache.org/docs/3.2.3/release-notes.html)

like image 173
farasath Avatar answered Oct 21 '22 01:10

farasath


I am facing the same problem. There are two solutions that I tried, and both works fine for me.

  • Update the Maven version repository (Maven version >= 3.2.3)
  • Restrict the current Maven version to use HTTPS links.

Update the Maven version repository:

Download the Apache Maven binary that includes the default https addresses (Apache Maven 3.6.3 binary). And open the Options dialog window in tools of NetBeans menu bar (Java Maven Dialog View). And select browse option in Maven Home List Box (Maven Home List Box View). After adding the Apache Maven newly downloaded version (Updated Maven Home List Box View), the project builds and runs successfully.

Restrict the current Maven version to use HTTPS links:

Include the following code in pom.xml of your project.

<project>
      ...
    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <updatePolicy>never</updatePolicy>
            </releases>
        </pluginRepository>
    </pluginRepositories>
    <repositories>
        <repository>
            <id>central</id>
            <name>Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>
like image 126
Muhammad umer Avatar answered Oct 21 '22 00:10

Muhammad umer