Maven is a Java-based tool, so the first thing to do is to install the JDK.
Maven 3.3 requires JDK 1.7 or above
Maven 3.2 requires JDK 1.6 or above
Maven 3.0/3.1 requires JDK 1.5 or above
The first step is to download the Maven package
Maven download address: http://maven.apache.org/download.cgi
Download and unzip locally
(I downloaded version 3.8.6 here)
The second step configures environment variables
Function: After setting the environment variable, the terminal and IDEA can automatically recognize it
Add the code to the .bash_profile file
Open the terminal (if the environment variable has been configured with .bash_profile), open the configuration file directly, the command is as follows:
open -e .bash_profile
⚠️If you configure environment variables for the first time, you need to create a .bash_profile file in the user's root directory,
#apache-maven-3.8.6环境变量配置
MAVEN_HOME="/Users/wangjiabao/environment/apache-maven-3.8.6"
PATH=$PATH:$MAVEN_HOME/bin
export MAVEN_HOME
export PATH
After saving and exiting, execute source on the console to make the configuration file take effect
#source后配置文件才会生效
source .bash_profile
#检查是否source成功 ==> 可以echo出来对应的内容就是设置成功
echo $MAVEN_HOME
Step 3 Alibaba Cloud Mirror Configuration
Purpose (Function): To speed up our download resources (it is recommended to use the mirror image of Alibaba Cloud in China).
Open apache-maven-3.8.6/conf/settings.xml
Add the following code block in the <mirrors></mirrors> tag
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<!--可以配多个镜像-->
Step 4 local warehouse configuration
Function: Build a local warehouse ( LocalRepository ) so that you don’t have to go to the remote warehouse to download resources every time.
The default local warehouse address is Default: ${user.home}/.m2/repository
We manually create a folder to store resource packs for easy management!
The first step is to create a folder
It is recommended to create a folder maven-repository under /apache-maven-3.8.6/, namely /apache-maven-3.8.6/maven-repository, and copy the path of maven-repository.
The second step, add configuration
在settings文件中<localRepository>标签中添加maven-repository的路径,并填入配置文件中即可。
<localRepository>maven-repository的路径</localRepository>
第五步 配置IDEA的全局MAVAEN
不打开项目,在欢迎页面进入偏好设置
这里设置后,以后新建的项目都是默认配置这个版本的maven环境。