安装篇-安装maven3.6.1
安装maven
因为idea安装好之后,就已经安装了对应的maven了,这个maven就是idea自己默认的maven。2019.3.3默认安装的maven版本是3.6.1。所以对于我们来说根本没有必要去maven官网去下载,然后再安装,我们只要配置一下maven的环境变量,和默认的配置文件setting.xml
即可。
配置环境变量
windows环境下配置环境变量
setx -m PATH "%PATH%;C:\usr\local\IJidea2019.3.3\plugins\maven\lib\maven3\bin;"
注意:这里的 C:\usr\local\IJidea2019.3.3 路径需要换成自己的idea安装路径。 我这个笔记是以前写的了,所以路径没有按照默认路径。正常的应该是在: C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.3
mac环境下配置环境变量
echo 'export PATH=$PATH:/Applications/IntelliJ\ IDEA.app/Contents/plugins/maven/lib/maven3/bin' >> ~/.bash_profile
接着,要使环境变量生效:
source ~/.bash_profile
然后要授权:
sudo chmod -R 777 /Applications/IntelliJ\ IDEA.app/Contents/plugins/maven/lib/maven3
永久生效:
echo 'source ~/.bash_profile' >> ~/.zshrc
setting.xml配置文件
maven配置文件setting.xml就跟mac和windows没关系了,一样配置。如下:
<?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">
<!--<localRepository>${user.home}/.m2/repository</localRepository>-->
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers></servers>
<mirrors>
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<mirror>
<id>central</id>
<name>Maven Repository Switchboard</name>
<url>http://repo1.maven.org/maven2/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
<mirror>
<id>ibiblio</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>
<mirror>
<id>jboss-public-repository-group</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles></profiles>
</settings>
这里配置了几个mirror镜像仓库,这样我们在下载依赖的时候会比去中央仓库下载快很多。 并且我没有配置本地仓库的位置,我觉得吧,就用默认的仓库也没什么不好,就是C盘用户目录下的 .m2目录下,这样 idea的maven配置就什么都不用改了,能省了很多事,很棒。