使用IDEA和Eclipse開發maven項目時,maven在添加一項新的依賴時,如果發現本地倉庫沒有,就會向位於國外服務器的中央倉庫下載。如果所處網絡沒有翻牆,下載速度會慢到你想原地爆炸。
這個時候奉勸你早點給maven配置個國內鏡像。配置方法很簡單,修改setting.xml(eg:D:\data\maven\apache-maven-3.2.3\conf)文件,配置國內鏡像(例如阿里雲鏡像),配置代碼如下:
<mirrors> <!-- mirror Specifies a repository mirror site to use instead of a given repository. The repository that this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used for inheritance and direct lookup purposes, and must be unique across the set of mirrors. <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>uk</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://uk.maven.org/maven2/</url> </mirror> <mirror> <id>CN</id> <name>OSChina Central</name> <url>http://maven.oschina.net/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>nexus</id> <name>internal nexus repository</name> <url>http://repo.maven.apache.org/maven2</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors>
配置完保存,重啟你的IDEA/eclipse,更新maven,會發現速度快的飛起,是不是覺得幸福來的有點突然?
