maven添加阿里云仓库。加速我们的maven下载速度
=====转。
现在maven开发已是主潮流,默认情况下,我们创建一个maven工程会在C盘自动生成一个maven仓库,只是我们从官网下载的maven包中的settings.xml文件配置默认用的是国际仓库,导致我们新建一个maven工程后下载包的速度非常非常慢,让人难以忍受,因此我们迫切需要提升maven的下载速度,这时使用阿里提供的镜像地址便是不错的选择。
首先我们从官网下载maven开发包,maven当前最新的版本是3.3.9,大家也可以到:http://download.****.net/detail/u012453843/9770164这个地址进行下载。
下面我们需要修改一下maven的settings.xml文件,只需做两处修改即可。
1.指定本地仓库的位置,(前提是我在E盘的根目录下新建了一个名叫m2的文件夹)如下红色粗体字所示。
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>E:\m2\repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
2.添加阿里云的镜像
<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>CN</id>
<name>OSChina Central</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
经过以上两步,我们便可以将我们的maven下载速度提升100倍左右!
使用IntellijIDEA作为开发工具的话,应该怎样配置maven呢?下面使用图例说明。
1.点击File----->Settings...如下图所示。
2.我们在弹出的框中的搜索框内输入maven搜索出maven,点击它会看到下图右侧的内容,我们勾选"Always update snapshots"前面的复选框,"Maven home directory"我们选择我们maven解压包所在的位置。"User settings file"就选择我们改过的settings.xml文件。"Local Repository"就选择我们在本地创建的仓库位置。设置完之后点击"Apply"和"OK"这时我们的maven将是今非昔比了,下载速度成百倍的提升!