可在pom.xml里面配置远程仓库,我们需要在什么时候配置远程仓库呢?当你连接中央仓库的速度比较慢时,或者你为你的公司搭建了自己的仓库,比如Nexus仓库管理(后面我会介绍),又或者你苏需要的jar存在另外一个公共仓库,比如我们配置一个国内的镜像地址
- <project>
- …
- <repositories>
- <repository>
- <id> maven-net-cn</id>
- <name> Maven China Mirror</name>
- <url> http://maven.net.cn/content/groups/public/</url>
- <releases>
- <enabled> true</enabled>
- </releases>
- <snapshots>
- <enabled> false</enabled>
- </snapshots>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id> maven-net-cn</id>
- <name> Maven China Mirror</name>
- <url> http://maven.net.cn/content/groups/public/</url>
- <releases>
- <enabled> true</enabled>
- </releases>
- <snapshots>
- <enabled> false</enabled>
- </snapshots>
- </pluginRepository>
- </pluginRepositories>
- …
- </project>
可以看到,允许配置多个repository和 plugin repository,
<releases>
<enabled>true</enabled>
</releases>
告诉Maven可以从这个仓库下载releases版本的构件,
而
<snapshots>
<enabled>false</enabled>
</snapshots>
告诉Maven不要从这个仓库下载snapshot版本的构件,之所以不让你从这个仓库下载snapshot版本,是因为这些版本是不稳定的.
如果一个公司会有很多的项目,每个项目都这样配置,可以直接配置在setting.xml中
- <settings>
- …
- <profiles>
- <profile>
- <id> myProfiel</id>
- <!—在这里加入<repositories>及<pluginRepositories>–>
- </profile>
- </profiles>
- <activeProfiles>
- <activeProfile> myProfiel </activeProfile>
- </activeProfiles>
- …
- </settings>