關於maven打包時的報錯: Return code is: 501 , ReasonPhrase:HTTPS Required.


今天使用jenkins構建時,報以下錯誤

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

  我們發現,這個依賴的文件在本地倉庫是有的,但是在構建過程中,在本地nexus下載完文件后,還是會像中央倉庫請求文件下載

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

  之后我們根據返回的501錯誤,去搜索問題,參考鏈接如下:

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

 

 

   上面提示,自2020年1月15日起,中央存儲庫不再支持通過純HTTP進行的不安全通信,並且要求對存儲庫的所有請求都通過HTTPS進行加密。

  於是我們在構建過程中所依賴的settings文件中,加入了一以下配置:

<mirror>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>https://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>

  但是問題依然沒有解決,接着報錯,錯誤如下:

    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]

  這個是在使用https協議請求中央倉庫時,需要指定協議版本,然后在構建時,加入了如下參數,參考鏈接如下: 

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

-Dhttps.protocols=TLSv1.2

  然后再次構建時,就通過請求了!

原因:我們Java環境用的是7和8兩種,而我們的mvn版本用的是3.5.x。

    所以,在JAVA8環境使用mvn打包時,不需要指定以上參數,但是使用JAVA7環境的時候,則會出現以上報錯。后面會考慮更新下mvn的版本及統一JAVA環境


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM