Maven构建项目速度太慢的解决办法

问题描述

通过idea新建maven项目,参数设置好后,idea自动构建maven项目时,速度很慢。

参数设置如图:

执行时间如下图:

Total time为8:49,花了将近十分钟时间。

连续尝试了几次,都是如此,感觉编辑器卡住了一样。

问题原因

[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml这一条语句执行了很久。

编辑器在执行mvn archetype:generate命令时,需要指定一个archetype-catalog.xml文件,该命令的参数为-DarchetypeCatalog,用来指定archetype-catalog.xml文件从哪里获取,可选值为:remote,internal,local,默认为remote,即从http://repo1.maven.org/maven2/archetype-catalog.xml路径下载archetype-catalog.xml文件,查看该文件可知,如下图:

该文件大小将近6M,在网速不理想情况下,由此方式下载势必会造成卡顿的情况。

速度测试

于是使用上述archetypeCatalog参数的三个数值remote,internal,local分别进行测试,得出如下结果:

  • 参数值为remote时,Total time为8:49,如图:

  • 参数值为internal时,Total time为1:19,如图:

  • 参数值为local时,Total time为4:01,如图:

当然,测试取样数值较少,且为网速较低时测试,得到的结果也只是一个大概情况,即internal优于local优于remote,可能网速较快时,误差可以忽略。

因此,修改配置时的archetypeCatalog参数值即可。

archetypeCatalog设置

1、remote为默认值,不需设置。

2、修改archetypeCatalog为internal,有以下两种方法:

  • 在新建maven项目时添加archetypeCatalog参数,并将值设置为internal

  • 直接修改maven配置参数,在使用mvn archetype:generate命令时,加上-DarchetypeCatalog=internal

3、修改archetypeCatalog为local前,需要先将archetype-catalog.xml下载至本地,并将此文件放至maven仓库目录下,设置archetypeCatalog为local时,同样有以下两种方法:

  • 在新建maven项目时添加archetypeCatalog参数,并将值设置为local

  • 直接修改maven配置参数,在使用mvn archetype:generate命令时,加上-DarchetypeCatalog=local

几种解决方法都已罗列出来,至于选哪种,就看你喜好啦,编程过程中无卡顿,美滋滋。

posted @ 2017-03-03 22:11  程序员十三  阅读(23931)  评论(1编辑  收藏  举报