1. 单独仓库配置 打开Maven配置文件 apache-maven-3.6.3\conf\settings.xml 在<mirrors></mirrors>标签里新增一个mirror配置即可。
| 
					 1 2 3 4 5 6 7 8  | 
						<mirrors>     <mirror>         <id>aliyun</id>         <name>aliyun maven</name>         <url>http://maven.aliyun.com/nexus/content/groups/public/</url>         <mirrorOf>central</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配置。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50  | 
						<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>标签启用配置。
| 
					 1 2 3 4 5  | 
						<activeProfiles>     <activeProfile>aliyun-repo</activeProfile>     <activeProfile>jboss-repo</activeProfile>     <activeProfile>maven-repo</activeProfile> </activeProfiles>  | 
					
from:https://www.aliang.link/pages/df2aeb/#_2-%E5%A4%9A%E4%BB%93%E5%BA%93%E9%85%8D%E7%BD%AE
View Details