作为一个小白,刚接触maven时候,有时候新建了一个maven项目,一打开就要一直卡在resolving dependencies。
上网查了相关博客,知道了因为是在国外的中央仓库下载依赖的,所以速度很慢,可以使用国内的镜像来解决此问题。也从网上查了国内镜像的配置代码。
但是仅仅在maven的配置文件setting.xml添加国内的几个镜像根本没有作用!!!因为还有重要的一步还没做
即使在maven的配置文件中加入国内的几个镜像,发现一直卡在resolving dependencies那里,而已也是辛辛苦苦等了好久好久才发现,原来下载地址还一直是国外的中央仓库:Downloading: http://repo.maven.apache.org/maven2/。
正确使用maven私有库下载依赖之后,发现用了大半天的时间,用国内镜像一下子就下载好了。这个问题困惑了我一天时间啊啊啊啊啊
正确使用maven私有库下载依赖的做法:
- 在maven的配置文件setting.xml中加入国内的镜像
- 在项目的pom.xml加入配置
- 注意:两个配置文件中的镜像id应该一致
setting.xml中加入的国内镜像代码如下:
<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>
pom.xml中加入的插件代码:
<repositories>
<repository>
<id>alimaven</id>
<url>https://maven.aliyun.com/repository/public</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>alimaven</id>
<url>https://maven.aliyun.com/repository/public</url>
</pluginRepository>
</pluginRepositories>
附上修改maven的相关参数VM options for importer加快resolving dependencies
File—>Settings—>Build,Execution,Deployment—>Build Tools—>maven—>Importing
将VM options for importer的默认768m修改为**-Xms1024m -Xmx2048m**