前提
已安装配置homebrew
homebrew安装配置可以参考本系列(三)
安装
brew search maven
brew install maven@3.5 #版本号自行选择

根据提示执行命令
echo 'export PATH="/usr/local/opt/maven@3.5/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc #重启path
配置
配置文件位置:
/usr/local/Cellar/maven@3.5/3.5.4_1/libexec/conf/settings.xml
说明
先提一句,后面的配置文件如果直接复制进去可能在使用的时候会因为格式(缩进,空格但看不出来)原因导致错误,类似下图

解决办法
我使用的办法是复制配置文件中的模板下来,然后直接修改

具体需要修改的配置:
国内镜像
<mirrors>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<mirror>
<!--This is used to direct the public snapshots repo in the
profile below over to a different nexus group -->
<id>nexus-public-snapshots</id>
<mirrorOf>public-snapshots</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
</mirrors>

仓库位置
#自定义位置即可,我这里是放在了maven安装目录下
<localRepository>/usr/local/Cellar/maven@3.5/3.5.4_1/repo</localRepository>

网友评论