在Maven构建项目的过程中如果需要某些构件,首先会到Maven的本地仓库中查找,如果找到则可以直接使用;如果找不到,它会自动连接外网,到远程中央仓库中查找;如果远程仓库中能找到,则先把所需要的插件下载到本地仓库,然后再使用,并且下次再用到相同的插件就可以直接使用本地仓库的;如果没有外网或者远程仓库中也找不到,则构建失败。
1.使用profile配置远程仓库
在settings.xml中
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
2.覆盖远程库
所有的POM都使用唯一的一个远程库,可以使用settings.xml中的mirror配置。
<mirror>
<!--This sends everything else to /public -->
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
注意:如果你想覆盖指定的远程创库那么你只需要改变id就可以了
比如你想覆盖中央库中央库的
id为central修改mirrorOf即可