How to Solve Maven Error: Return code is: 501 , ReasonPhrase:HTTPS Required.

When using jenkins to build today, the following error was reported

  [ERROR] Failed to execute goal on project saas20: Could not resolve dependencies for project com.ipower365.saas:saas20:war:0.0.1-SNAPSHOT: Failed to collect dependencies at com.ipower365.saas:messageserviceimpl:jar:0.0.1-SNAPSHOT -> com.ipower365.boss:nacha:jar:1.0.1: Failed to read artifact descriptor for com.ipower365.boss:nacha:jar:1.0.1: Could not transfer artifact com.ipower365.boss:nacha:pom:1.0.1 from/to central (http://repo1.maven.org/maven2/):Failed to transfer file:http://repo1.maven.org/maven2/com/ipower365/boss/nacha/1.0.1/nacha-1.0.1.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]

We found that this dependent file is available in the local warehouse, but during the build process, after downloading the file in the local nexus, it will still request the file download like the central warehouse.

    [echoing saas20] Downloading from central: http://repo1.maven.org/maven2/com/ipower365/boss/nacha/1.0.1/nacha-1.0.1.pom

After that, we searched for the problem based on the returned 501 error. The reference link is as follows:

https://stackoverflow.com/questions/59763531/maven-dependencies-are-failing-with-501-error

 

 

As mentioned above, since January 15, 2020, the central repository no longer supports insecure communication via pure HTTP, and requires all requests to the repository to be encrypted via HTTPS.

So we added the following configuration to the settings file that we relied on during the build process:

1
2
3
4
5
6
<mirror>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>https://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>

But the problem is still not resolved, and then an error is reported, the error is as follows:

    Could not transfer artifact com.ipower365.boss:nacha:pom:1.0.1 from/to central (https://repo1.maven.org/maven2/):Received fatal alert: protocol_version -> [Help 1]

This is when using the https protocol to request the central warehouse, the protocol version needs to be specified, and then the following parameters are added when building, the reference link is as follows: 

https://stackoverflow.com/questions/50824789/why-am-i-getting-received-fatal-alert-protocol-version-or-peer-not-authentic

1
-Dhttps.protocols=TLSv1.2

Then when you build again, the request is passed!

Reason: Our Java environment uses 7 and 8, while our mvn version uses 3.5.x.

Therefore, when using mvn packaging in the JAVA8 environment, the above parameters do not need to be specified, but when using the JAVA7 environment, the above error will occur. Later, we will consider updating the version of mvn and unified JAVA environment

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *