settings.xml文件一般存在于两个位置: 全局配置: ${M2_HOME}/conf/settings.xml 用户配置: 𝑢𝑠𝑒𝑟.ℎ𝑜𝑚𝑒/.𝑚2/𝑠𝑒𝑡𝑡𝑖𝑛𝑔𝑠.𝑥𝑚𝑙𝑛𝑜𝑡𝑒:用户配置优先于全局配置。user.home/.m2/settings.xmlnote:用户配置优先于全局配置。{user.home} 和和所有其他系统属性只能在3.0+版本上使用。请注意windows和Linux使用变量的区别。
需要注意的是:局部配置优先于全局配置。 配置优先级从高到低:pom.xml> user settings > global settings 如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。
下面列举了settings.xml中的顶级元素
<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>
<https://maven.apache.org/xsd/settings-1.0.0.xsd>">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
作用:该值表示构建系统本地仓库的路径。 其默认值:~/.m2/repository。
<localRepository>${user.home}/.m2/repository</localRepository>
作用:表示maven是否需要和用户交互以获得输入。 如果maven需要和用户交互以获得输入,则设置成true,反之则应为false。默认为true。
<interactiveMode>true</interactiveMode>
作用:maven是否需要使用plugin-registry.xml文件来管理插件版本。 如果需要让maven使用文件~/.m2/plugin-registry.xml来管理插件版本,则设为true。默认为false。
<usePluginRegistry>false</usePluginRegistry>
作用:表示maven是否需要在离线模式下运行。 如果构建系统需要在离线模式下运行,则为true,默认为false。 当由于网络设置原因或者安全因素,构建服务器不能连接远程仓库的时候,该配置就十分有用。
<offline>false</offline>