最近在看《maven实战》这本书,想着将现在做的项目使用模块化方式,其中有几个依赖是使用公司的自建仓库,为了方便多个公司的合作,并尽量减少其他人的操作,就想将公司的的仓库放着项目中pom,这样其他人不用配置自己本地的setting.xml文件,就可以引用我公司的仓库。
使用过程中发现一个问题,就是已经按照书中的方式进行了配置公司仓库信息,但是仍然不能在我司仓库下载,然后经过各方搜索,发现了是mirror(镜像)和repository(仓库)的配置问题。
由于之前发现maven中央仓库,在国内访问比较慢,于是使用了开源中国的maven仓库(请参考这里的配置帮助),其中有一段关于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>nexus-osc</id>
<mirrorOf>nexus,osc</mirrorOf>
<name>Nexus osc</name>
<url>http://maven.oschina.net/content/groups/public/</url>
</mirror>
</mirrors>
正是由于这段配置导致在项目中配置repository不能正常访问。在查看mirror和repository的区别后(参考这里或这里),发现了原因:<mirrorOf>*</mirrorOf> 表示所有的仓库都要使用此镜像,而我公司的仓库不在这个镜像下,导致获取失败。
现修改如下为<mirrorOf>nexus,osc</mirrorOf>后,项目中配置repository可以正常访问了。
PS:主要是记录个人的感受,写的有点繁琐。




