Maven单、多仓库配置
1. 单独仓库配置
- 打开Maven配置文件
apache-maven-3.6.3\conf\settings.xml
- 在
<mirrors></mirrors>
标签里新增一个mirror
配置即可。
<mirrors>
<mirror>
<id>aliyun</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
标签 | 作用 |
---|---|
id | 镜像的唯一标识 |
name | 名称描述 |
url | 地址 |
mirrorOf | 指定镜像规则,什么情况下从镜像仓库拉取 |
mirrorOf规则 | 作用 |
---|---|
* | 匹配所有,所有内容都从镜像拉取 |
external:* | 除了本地缓存的所有从镜像仓库拉取 |
central | 覆盖默认的仓库 |
repo1,repo2 | 匹配仓库repo1和repo2,使用逗号分割多个远程仓库 |
比如:镜像配置的规则 <mirrorOf>repo1</mirrorOf>
,意为:匹配到目标仓库 <id>repo1</id>
;
所以maven认为目标仓库central被镜像了; 不再去 https://repo.maven.apache.org/maven2/ 地址下载jar包;
而是去镜像仓库 http://maven.aliyun.com/nexus/content/groups/public/ 下载jar包。
2. 多仓库配置
有时候我们需要的jar包公有仓库没有,此时就必须启用多仓库配置,使maven同时使用私有仓库和公有仓库。
- 在
<profiles></profiles>
标签里配置多个profile
配置。
<profiles>
<profile>
<id>aliyun-repo</id>
<repositories>
<repository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>jboss-repo</id>
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>maven-repo</id>
<repositories>
<repository>
<id>maven2</id>
<url>http://central.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profiles>
- 在
<activeProfiles></activeProfiles>
标签里使用<activeProfile></activeProfile>
标签启用配置。
<activeProfiles>
<activeProfile>aliyun-repo</activeProfile>
<activeProfile>jboss-repo</activeProfile>
<activeProfile>maven-repo</activeProfile>
</activeProfiles>