maven中的仓库的配置与优先级

文章目录

  • [1 仓库的具体配置](#1 仓库的具体配置)
    • [1.1 settings.xml配置本地仓库](#1.1 settings.xml配置本地仓库)
    • [1.2 pom.xml配置的仓库](#1.2 pom.xml配置的仓库)
    • [1.3 settings.xml配置mirror镜像](#1.3 settings.xml配置mirror镜像)
    • [1.4 settings.xml配置profile仓库](#1.4 settings.xml配置profile仓库)
  • [2 结论](#2 结论)
    • [2.1 mirror中不代理`*`的拉取顺序](#2.1 mirror中不代理*的拉取顺序)
    • [2.2 mirror中代理了`*`的拉取顺序](#2.2 mirror中代理了*的拉取顺序)

1 仓库的具体配置

1.1 settings.xml配置本地仓库

xml 复制代码
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
	<localRepository>D:\Program Files\apache-maven-3.6.3\conf\repository</localRepository>
</settings>

1.2 pom.xml配置的仓库

xml 复制代码
<project>
    <repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
    </repositories>
</project>

1.3 settings.xml配置mirror镜像

xml 复制代码
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<mirrors>
		<mirror>
			<id>aliyun-central</id>
			<name>aliyun-central</name>
			<mirrorOf>central</mirrorOf>
			<url>https://maven.aliyun.com/repository/central</url>
		</mirror>
		<mirror>
			<id>aliyun-spring</id>
			<name>aliyun-spring</name>
			<mirrorOf>spring</mirrorOf>
			<url>https://maven.aliyun.com/repository/spring</url>
		</mirror>
		<mirror>
			<id>aliyun-spring-plugin</id>
			<name>aliyun-spring-plugin</name>
			<mirrorOf>spring-plugin</mirrorOf>
			<url>https://maven.aliyun.com/repository/spring-plugin</url>
		</mirror>
	</mirrors>
</settings>

1.4 settings.xml配置profile仓库

xml 复制代码
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<servers>
		<server>
			<id>nexus-server</id>
			<username>uname</username>
			<password>pwd</password>
		</server>
	</servers>
	
	<profiles>
		<profile>
			<id>nexus</id>
			<repositories>
				<repository>
					<id>nexus-server</id>
					<name>Nexus Repository</name>
					<url>https://maven.nexus.com/repository/maven-public/</url>
					<snapshots>
						<enabled>true</enabled>
						<updatePolicy>always</updatePolicy>
					</snapshots>
				</repository>
			</repositories>
		</profile>
	</profiles>

	<!--让配置生效-->
	<activeProfiles>
		<activeProfile>nexus</activeProfile>
	</activeProfiles>
</settings>

2 结论

2.1 mirror中不代理*的拉取顺序

  1. settings.xml->本地仓库,如果没有则向下找
  2. settings.xml->profile中的仓库,如果没有则向下找
  3. pom.xml配置的仓库,如果没有则向下找
  4. settings.xml->mirror中代理central的仓库

2.2 mirror中代理了*的拉取顺序

mirror中一旦代理了*,则该配置优先级最高,其他的都不会走了。

但是有一种情况除外,就是mirror中代理了central仓库,那么如果代理*的 mirror中没有,则会找代理的central仓库

  1. settings.xml->本地仓库,如果没有则向下找
  2. settings.xml->mirror中代理*的仓库,如果没有则向下找
  3. settings.xml->mirror中代理central的仓库
相关推荐
云泽808几秒前
C/C++内存管理详解:从基础原理到自定义内存池原理
java·c语言·c++
Code小翊9 分钟前
堆的基础操作,C语言示例
java·数据结构·算法
高山上有一只小老虎27 分钟前
idea中设置快捷键风格
java·ide·intellij-idea
JH307328 分钟前
IDEA自带的Maven安装位置
java·maven·intellij-idea
梵得儿SHI1 小时前
Java 反射机制核心类详解:Class、Constructor、Method、Field
java·开发语言·反射·class·constructor·java反射·java反射机制
m0_736927041 小时前
想抓PostgreSQL里的慢SQL?pg_stat_statements基础黑匣子和pg_stat_monitor时间窗,谁能帮你更准揪出性能小偷?
java·数据库·sql·postgresql
Jabes.yang1 小时前
Java面试大作战:从缓存技术到音视频场景的探讨
java·spring boot·redis·缓存·kafka·spring security·oauth2
Query*1 小时前
Java 设计模式——适配器模式进阶:原理深挖、框架应用与实战扩展
java·设计模式·适配器模式
Sirens.1 小时前
Java核心概念:抽象类、接口、Object类深度剖析
java·开发语言·github
Meteors.1 小时前
23种设计模式——中介者模式 (Mediator Pattern)详解
java·设计模式·中介者模式