Maven项目对象模型(POM-Project Object Model),可以通过一小段描述信息来管理项目的构建,报告和文档的项目管理工具软件。
软件版本:
IntelliJ IDEA 2019.2.4 (Ultimate Edition)
apache-maven-3.6.3-bin.zip
IDEA 内置的 Maven:
在IDEA中,maven的默认配置是如下图
Maven home directory :maven的家目录,可以选择IDEA自带的版本,亦或是选择我们自己下载的版本(解压后的目录)。
User settings file :用户配置文件,默认是 C:\Users\Administrator\.m2\settings.xml
Local repository :本地源目录,默认是 C:\Users\Administrator\.m2\repository
此外,我们在项目下,还会编辑一个pom.xml配置文件。
系统安装的 Maven:
也可以到maven官网下载安装
https://maven.apache.org/download.cgi
解压后的文件内容如下
还需要配置系统环境变量
M2_HOME=E:\Software\java_software\apache-maven\apache-maven-3.6.3
还需要在 “Path” 环境变量里添加 Mavin的bin目录,即
%M2_HOME%\bin
在cmd下输入mvn -v ,能正确显示版本号就安装好了。
现在我们再来看看系统版本的maven的配置文件目录
settings.xml文件是干什么的,为什么要配置它呢?
从settings.xml的文件名就可以看出,它是用来设置maven参数的配置文件。并且,settings.xml是maven的全局配置文件。而pom.xml文件是所在项目的局部配置。
Settings.xml中包含类似本地仓储位置、修改远程仓储服务器、认证信息等配置。
settings.xml文件位置
settings.xml文件一般存在于两个位置:
全局配置: ${M2_HOME}/conf/settings.xml
用户配置: ${user.home}/.m2/settings.xml
note:用户配置优先于全局配置。${user.home} 和和所有其他系统属性只能在3.0+版本上使用。请注意windows和Linux使用变量的区别。
配置优先级
需要注意的是:局部配置优先于全局配置。
配置优先级从高到低:pom.xml> user settings > global settings
如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。
主配置文件 settings.xml
默认情况下,settings.xml 里面的内容都是注释掉的,下面我们来详细看看这个配置文件。
settings.xml 的内容主要分为以下几部分标签:
- settings
- localRepository
- interactiveMode
- offline
- pluginGroups
- proxies
- servers
- mirrors
- profiles
- activeProfiles
下面是去掉掉注释后的配置文件内容:
<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>/path/to/local/repo</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<pluginGroups>
<pluginGroup>com.your.plugins</pluginGroup>
</pluginGroups>
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxie