今天把一個去年沒作完的項目翻出來作時,發現maven沒法正常導入依賴。檢查了一遍項目配置,沒發現有什麼問題。並且依賴在本地倉庫存在。maven
隨後發現報錯:Failed to transfer file:*********. Return code is: 501 , ReasonPhrase:HTTPS Required. 這時候好像發現了什麼重點————咱們須要將maven配置修改一下:ide
<!-- 中央倉庫1 --> <mirror> <id>repo1</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>https://repo1.maven.org/maven2/</url> </mirror> <!-- 中央倉庫2 --> <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>https://repo2.maven.org/maven2/</url> </mirror>
隨後發現能夠正常導入依賴了。ui
在stackoverflow上查了下,發現有人也遇到了這個問題:this
Recently Maven build jobs running in Jenkins are failing with the below exception saying that they could not pull dependencies from Maven Central and should use HTTPS. I am not sure how to change the requests from HTTP to HTTPS. Could someone guide me on this matter?
回答以下:url
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.
因此這個問題的根源就是maven中央倉庫如今只支持HTTPS協議,咱們改一下就行。spa