maven修改远程和本地仓库地址

原文地址:https://www.cnblogs.com/waterlufei/p/6498526.html

参考文章:https://blog.csdn.net/qq_27093465/article/details/52957253

简介

我们用maven的时候,从maven自带的远程中央仓库中下载依赖经常会特别慢,还有默认本地仓库是在 C盘 C:\Users\你的电脑用户账号\.m2\repository 目录,对于有强迫症的人,总是看着让人感觉不爽。

 下面我就来介绍一下如何对这两个地址进行配置,我的环境:

Maven 3.3.9

JDK 1.8_112

Intellij IDEA 2016.3

Windows 10

SpringBoot 1.5.1

maven修改远程中央仓库地址

找到你的maven安装位置,找到conf目录下的setting.xml,我的位置 D:\maven\apache-maven-3.3.9\conf\setting.xml,打开它,我这里用的sublime3,默认很多都注释了,加入代码:

	<profiles>
		<profile>
			<id>dev</id>
			<!-- repositories and pluginRepositories here -->
			<repositories>
				<repository>
					<id>nexus-aliyun</id>
					<name>Nexus aliyun</name>
					<url>http://maven.aliyun.com/nexus/content/groups/public</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
		</profile>
	</profiles>
	<activeProfiles>
		<activeProfile>dev</activeProfile>
	</activeProfiles>

在这里我们用的是阿里的maven远程中央仓库,试验过网速杠杠的,这个时候可以去试验下你的maven下载,看是不是阿里的远程仓库地址。

maven修改本地仓库地址

还是在这个setting.xml文件,搜索localRepository:

在下面加入一行<localRepository>D:\down\maven-repository\repository</localRepository>,这里是我自己的maven本地仓库地址,改成自己设置的maven本地仓库地址。

然后将setting.xml(maven安装的位置D:\maven\apache-maven-3.3.9\conf\setting.xml),复制一份到你设置的maven本地仓库地址下,这里的地址是D:\down\maven-repository\repository,配置完成了打开intellij idea,打开file->setting,搜索maven。

将这三处修改,第一处是使用自己安装的maven,这个地方有maven2、maven3、maven3.3.9(自己安装的)可供选择,选择maven3.3.9;第二处是使用自己配置的放在本地仓库的setting.xml文件;第三处是本地仓库的地址。配置完成,点击apply,ok。

然后可以移动下自己pom.xml中的内容,右下角有下载信息,会显示从阿里云仓库下载到自己定义的仓库地址。

POM修改项目仓库地址

</project>	
	//...
	<repositories>
		<repository>
			<id>nexus-aliyun</id>
			<name>Nexus aliyun</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>nexus-aliyun</id>
			<name>Nexus aliyun</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<releases>
				<enabled>true</enabled>
			</releases>
		</pluginRepository>
	</pluginRepositories>
	//...
</project>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值