maven中mirror和repository配置略解

在Java开发中,Maven用于管理依赖。为提高效率,通常配置Maven的settings.xml文件,添加私有仓库的repository信息,并使用阿里云的镜像地址作为国内下载的首选,以解决maven中央仓库速度慢的问题。mirror配置起到反向代理作用,通过mirrorOf指定镜像仓库代理哪些repository。示例配置展示了如何设定阿里镜像为中央仓库的镜像源。
摘要由CSDN通过智能技术生成

概述

java开发中,经常用maven来管理依赖。

maven私有仓库获取依赖时,需要配置mavensetting.xml
其中就会需要配置setting.xmlprofile标签下的私服的repository信息.

而且因为maven中央仓库下载依赖太慢,网上一般建议配置阿里等国内的镜像地址.

maven仓库优先级:

  1. 本地仓库(localRepositories)
  2. profile中的repositories仓库
  3. POM中的repository
  4. mirrors全局仓库

mirror和repository关系

先说repository,顾名思义,就是仓库的意思,mavensetting.xml中有个默认仓库就是maven中央仓库.
repositories下会有多个仓库,maven会依次请求,第一个不可用则会使用第二个

标识我们下载依赖的时候都从这个仓库去下载,但是国内下载太慢,就会建议mirror中配置上阿里的地址,这里我们可以理解为mirror就像nginx的反向代理,我们去下载依赖的时候,其实是从阿里的镜像仓库去下载的。

这里就要说到这个repositoryidmirror中的mirrorOf标签,这两个是对应的,代表mirror需要代理哪个仓库.
<mirrorOf>*</mirrorOf>代表所有repository仓库都走这个镜像仓库.

配置demo如下

<mirror>
  <id>alimaven</id>
  <name>aliyun maven</name>
  <!--mirrorOf的配置很重要后面会详细说明-->
  <mirrorOf>central</mirrorOf>
  <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>

<profiles>
	<profile>
		<id>配置文件id</id>
		<repositories>
		  <!--maven默认的内置仓库(maven中央仓库)-->
		  <repository>
		   <id>central</id>
		   <name>Central Repository</name>
		   <url>https://repo.maven.apache.org/maven2</url>
		   <layout>default</layout>
		   <snapshots>
		    <enabled>false</enabled>
		   </snapshots>
		  </repository>
		</repositories>
	<profile>
</profiles>

<activeProfiles>
  <!--默认的配置文件-->
  <activeProfile>配置文件id</activeProfile>
</activeProfiles>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值