Maven 阿里云仓库使用小技巧
简介
平时工作或者学习中经常需要看下别人的工程示例代码,但maven的依赖导入经常有些问题,maven镜像使用默认是国外的,众所周知慢的离谱,有时候出门散个步回来,还没有导入完成,导致摸鱼时间过多。
使用国内的镜像那就会快非常非常多,快则两三分钟、慢则十多分钟,可以接受。但在使用的过程中也会遇到许多问题,比如设置和依赖找不到的问题,下面介绍下自己使用阿里云的一些技巧,希望对大家有所启发
阿里云仓库配置
第一步是配置镜像仓库为阿里云,有两种配置方法,一个是全局配置,另一个是单个工程配置
推荐使用全局配置,新建两个全局配置文件,配合idea进行切换就比较方便好用
全局配置
使用进入maven安装位置的conf目录下,复制一份 setting.xml,命名为 setting.aliyun.xml,打开文件,在标签中添加 mirror 子节点,在里面添加如下内容,大致如下:
<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>
-->