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

 更新时间:2025年07月23日 09:35:50   作者:L-960  
本文介绍Maven仓库配置,包括settings.xml和pom.xml中的本地仓库、镜像及profile设置,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习吧

1 仓库的具体配置

1.1 settings.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配置的仓库

<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镜像

<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仓库

<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中不代理*的拉取顺序

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

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

mirror中一旦代理了*,则该配置优先级最高,其他的都不会走了。
但是有一种情况除外,就是mirror中代理了central仓库,那么如果代理*的 mirror中没有,则会找代理的central仓库

  • settings.xml->本地仓库,如果没有则向下找
  • settings.xml->mirror中代理*的仓库,如果没有则向下找
  • settings.xml->mirror中代理central的仓库

到此这篇关于maven中仓库的配置与优先级的实现的文章就介绍到这了,更多相关maven 仓库配置与优先级内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! 

相关文章

  • Java线程同步机制_动力节点Java学院整理

    Java线程同步机制_动力节点Java学院整理

    在之前,已经学习到了线程的创建和状态控制,但是每个线程之间几乎都没有什么太大的联系。可是有的时候,可能存在多个线程多同一个数据进行操作,这样,可能就会引用各种奇怪的问题。现在就来学习多线程对数据访问的控制吧
    2017-05-05
  • java网上图书商城(4)购物车模块1

    java网上图书商城(4)购物车模块1

    这篇文章主要为大家详细介绍了java网上图书商城,购物车模块,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-12-12
  • 基于Map的computeIfAbsent的使用场景和使用方式

    基于Map的computeIfAbsent的使用场景和使用方式

    这篇文章主要介绍了基于Map的computeIfAbsent的使用场景和使用方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-09-09
  • SpringBoot+SpringCache实现两级缓存(Redis+Caffeine)

    SpringBoot+SpringCache实现两级缓存(Redis+Caffeine)

    这篇文章主要介绍了SpringBoot+SpringCache实现两级缓存(Redis+Caffeine),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-04-04
  • SpringBoot整合Spring Security过滤器链加载执行流程源码分析(最新推荐)

    SpringBoot整合Spring Security过滤器链加载执行流程源码分析(最新推荐)

    Spring Boot 对于 Spring Security 提供了自动化配置方案,可以使用更少的配置来使用 Spring Security,这篇文章主要介绍了SpringBoot整合Spring Security过滤器链加载执行流程源码分析,需要的朋友可以参考下
    2023-02-02
  • MyBatis中criteria的or(或查询)语法说明

    MyBatis中criteria的or(或查询)语法说明

    这篇文章主要介绍了MyBatis中criteria的or(或查询)语法说明,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2021-12-12
  • Java Lambda List转Map代码实例

    Java Lambda List转Map代码实例

    这篇文章主要介绍了Java Lambda List转Map代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-03-03
  • 使用IDEA创建maven父子工程项目 (图文)

    使用IDEA创建maven父子工程项目 (图文)

    本文主要介绍了使用IDEA创建maven父子工程项目,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-04-04
  • 使用BigDecimal除法后保留两位小数

    使用BigDecimal除法后保留两位小数

    这篇文章主要介绍了使用BigDecimal除法后保留两位小数方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-06-06
  • SpringBoot MDC全链路调用日志跟踪实现详解

    SpringBoot MDC全链路调用日志跟踪实现详解

    这篇文章主要为大家介绍了SpringBoot MDC全链路调用日志跟踪实现详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-02-02

最新评论