1.確認maven是否正正常安裝,是否配置了環境變量,可以通過命令 mvn -version 看是否顯示maven的版本信息。
2.檢查maven的setting.xml配置文件中本地倉庫位置配置是否正確(主要是倉庫位置是否存在),以及鏡像配置(是否指定相應的中央倉庫)是否正確。
- 本地倉庫位置配置:
<localRepository>D:\devTool\meavn\rep\ideaRepository</localRepository> - 鏡像mirror配置(注意:如果http協議下載不了jar包,把它改成https協議)
<mirror>
<id>nexus</id>
<name>internal nexus repository</name>
<!-- <url>https://192.168.1.100:8081/nexus/content/groups/public/</url>-->
<url>https://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
3.檢查idea中的maven設置是否正確,檢查安裝根路徑是否正確,setting.xml配置文件位置是否正常,本地倉庫位置是否正確,是否有遠程倉庫的url,如果沒有,則不能下載依賴jar包

idea設置maven注意事項:設置本地倉庫不能馬上生效,必須在創建項目是再指定一次才能生效,不然maven會自動生成一個本地倉庫,jar包直接下載在默認的本地倉庫。如果某個項目已經存在,想換一個本地倉庫,必須將項目刪除,重新創建時指定新的本地倉庫。

4.臨時解決方案:在pom.xml配置文件中直接指定阿里中央倉庫。
<repositories>
<repository>
<id>alimaven</id>
<name>Maven Aliyun Mirror</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
