更改Maven LocalRepository本地仓库位置;远程仓库更改为阿里云镜像(Idea、STS4)

下载某个版本的Maven

选择下载某个版本的Maven-bin.zip文件:
https://dlcdn.apache.org/maven/maven-3/

注意:如果IDEA版本比较低(比如2020以前的版本),建议Maven版本不能过高,最好Maven版本不超过3.6.1,否则报错。

MAVEN_HOME环境变量设置

MAVEN_HOME=D:\env\java\apache-maven-3.3.9
然后将%MAVEN_HOME%\bin添加到PATH环境变量后面。

mvn -v

验证安装是否成功。

Idea Maven本地仓库设置

File–Settings–搜索Maven–User settings file,勾选Override,选择使用文末更改过的的settings.xml文件。

这样设置后,每次新建项目,新项目中Maven仓库还是默认地址(比如,C盘~/.m2/repository)。
一劳永逸的方式:
**File–Other Settings–Settings for New Projects…**重新设置一遍。

STS4 Maven本次仓库设置

STS4(Spring Tool Suite 4)自带一个maven,不过maven本地仓库的默认地址在C盘~/.m2/repository,其中~表示用户的根目录,一般是C:/Users/xxx
更改STS4 maven本地仓库位置的方法如下:

STS4–Preferences–Maven–User Settings

sts4

最后,附一个settings.xml文件,链接阿里云的镜像服务器,提高下载速度:

<?xml version="1.0" encoding="utf-8"?>
<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">
	<!--本地仓库。该值表示构建系统本地仓库的路径。其默认值为~/.m2/repository。  -->
	<localRepository>D:/env/repo/.m2/repository</localRepository>
	 
	<!--Maven是否需要和用户交互以获得输入。如果Maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。  
	<interactiveMode>true</interactiveMode>  -->
	<mirrors>
		<mirror>
			<id>nexus-aliyun</id>
			<mirrorOf>central</mirrorOf>
			<name>Nexus aliyun</name>
			<url>http://maven.aliyun.com/nexus/content/repositories/central</url>
		</mirror>
		<mirror>
			<id>net-cn</id>
			<mirrorOf>central</mirrorOf>
			<name>Nexus net</name>
			<url>http://maven.net.cn/content/groups/public/</url>
		</mirror>
	</mirrors>
	  
	<profiles>
		<profile>
			<repositories>
				<repository>
					<id>nexus</id>
					<name>local private nexus</name>
					<url>http://maven.aliyun.com/nexus/content/repositories/central</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
				<pluginRepository>
					<id>nexus</id>
					<name>local private nexus</name>
					<url>http://maven.aliyun.com/nexus/content/repositories/central</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
	<!-- -->
	<activeProfiles>
		<activeProfile>nexus</activeProfile>
	</activeProfiles>
</settings>
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值