一、配置级别
1. 全局:一台机器上所有 Maven 用户
~~\apache-maven-3.5.2\conf\settings.xml
2. 单个 Maven 用户
~~.m2\settings.xml
3. 项目:pom.xml
二、同一配置属性优先级(不同配置属性合并)
项目 > 用户 > 全局
三、元素解析
<?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">
<!--
| 本地仓库地址
|
| 默认: ${user.home}/.m2/repository
-->
<localRepository>/path/to/local/repo</localRepository>
<!--
| maven 是否需要和用户交互以获得输入
|
| Default: true
-->
<interactiveMode>true</interactiveMode>
<!--
| 表示maven是否需要在离线模式下运行
| 当由于网络设置原因或者安全因素,构建服务器不能连接远程仓库的时候,该配置就十分有用。
|
| Default: false
-->
<offline>false</offline>
<!--
| 当插件的 groupId 没有显式提供时,供搜寻插件的 groupId 列表
| 该元素包含一个 pluginGroup 元素列表,每个子元素包含了一个 groupId
|
| 默认: org.apache.maven.plugins 和 org.codehaus.mojo
|-->
<pluginGroups>
<pluginGroup>org.codehaus.mojo</pluginGroup>
</pluginGroups>
<!-- 用来配置不同的代理 -->
<proxies>
<!-- 一种代理规范,用于连接到网络 -->
<proxy>
<!--代理的唯一定义符,用来区分不同的代理元素。 -->
<id>optional</id>
<!--该代理是否是激活的那个。true 则激活代理。当我们声明了一组代理,而某个时候只需要激活一个代理的时候,该元素就可以派上用处。 -->
<active>true</active>
<!--代理的协议 -->
<protocol>http</protocol>
<!--代理的主机名 -->
<host>proxy.host.net</host>
<!--代理的端口 -->
<port>80</port>
<!--代理的用户名 -->
<username>proxyuser</username>
<!--代理的密码 -->
<password>proxypass</password>
<!--不该被代理的主机名列表。该列表的分隔符由代理服务器指定;例子中使用了竖线分隔符,使用逗号分隔也很常见。 -->
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
<!--
| 一般,仓库的下载和部署是在 pom.xml 文件中的 repositories 和 distributionManagement 元素中定义的。
| 然而,一般类似用户名、密码(有些仓库访问是需要安全认证的)等信息不应该在 pom.xml 文件中配置,这些信息可以配置在 settings.xml 中。
|-->
<servers>
<!-- 用户名/密码 方式 -->
<server>
<!-- 这是 server 的 id,与 distributionManagement 中 repository 元素的 id 相匹配。 -->
<id>deploymentRepo</id>
<!-- 鉴权用户名 -->
<username>repouser</username>
<!-- 鉴权密码 -->
<password>repopwd</password>
</server>
<!-- privateKey 方式 -->
<server>
<id>siteServer</id>
<!-- 鉴权时使用的私钥位置,私钥位置和私钥密码指定了一个私钥的路径(默认是${user.home}/.ssh/id_dsa)以及如果需要的话,一个密语。将来passphrase和password元素可能会被提取到外部,但目前它们必须在settings.xml文件以纯文本的形式声明。 -->
<privateKey>/path/to/private/key</privateKey>
<!-- 鉴权时使用的私钥密码 -->
<passphrase>optional; leave empty if not used.</passphrase>
</server>
</servers>
<!-- 镜像仓库, 用来代替 Maven 默认的中央仓库,用于提升传输速度 -->
<mirrors>
<mirror>
<!-- 唯一标识符 -->
<id>mirrorId</id>
<!-- 镜像名称 -->
<name>Human Readable Name for this Mirror.</name>
<!-- 镜像的URL, 构建系统会优先考虑使用该URL,而非使用默认的服务器URL -->
<url>http://my.repository.com/repo/path</url>
<!-- 被镜像的服务器的id。例如,如果我们要设置了一个Maven中央仓库(http://repo.maven.apache.org/maven2/)的镜像,就需要将该元素设置成central。这必须和中央仓库的id central完全一致。 -->
<mirrorOf>repositoryId</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<!-- profile 的唯一标识 -->
<id>env-dev</id>
<!-- 自动触发 profile 的条件逻辑 -->
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<!-- 扩展属性列表 -->
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
<JAVA_HOME>D:\Program Files\Java\jdk1.7.0_10</JAVA_HOME>
</properties>
<!-- 远程仓库列表 -->
<repositories>
<!-- 私有库地址-->
<repository>
<!-- 唯一标识 -->
<id>public</id>
<url>http://192.168.0.124:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- 插件仓库列表 -->
<pluginRepositories>
<!--插件库地址-->
<pluginRepository>
<id>public</id>
<url>http://192.168.0.124:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- 手动激活 profiles 的列表,按照 profile 被应用的顺序定义 activeProfile -->
<activeProfiles>
<!-- 要激活的 profile id -->
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
</settings>