查看当前命令行生效的settings.xml
用mvn help:effective-settings可以查看当前生效的settings.xml
maven命令行窗口指定特定settings.xml
mvn install --settings c:\user\settings.xml
maven报错 java.lang.RuntimeException: com.google.inject.CreationException: Unable to create injector, see the following errors
据网上说,这里很可能是由于版本不兼容导致的。
于是我卸载maven3.6.2,重新下载了maven3.6.0版本,亲测有效。
maven的setting配置文件中mirror和repository的区别
mirror是远程仓库的镜像地址,通过mirrorOf来指定代理的远程镜像(central、*、或者其他)
其中pom依赖默认是central中央仓库
主:maven 安装目录下有个超级pom 超级POM:\org\apache\maven\model\pom-4.0.0.xml
里面有关于central 的定义
repository指远程仓库地址配置 可以配置在setting或则pom中(一个全局 一个项目 优先级是项目最高)
如果仓库id存在镜像mirrorOf匹配那么仓库地址配置会失效 默认会走代理地址(即不会再从仓库配置地址而是从对应镜像地址取依赖包)
还有一点需要理解的是,当我们运行install的时候,Maven实际上是将项目生成的构件安装到了本地仓库,也就是说,只有install了之后,其它项目才能使用此项目生成的构件。
profile 一定要激活 即使只有一个profile
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
接着了解一下Maven缺省的远程仓库,即Maven中央仓库:
安装好Maven之后,我们可以建立一个简单的项目,配置一些简单的依赖,然后运行mvn clean install,项目就构建好了。我们没有手工的去下载任何jar文件,这一切都是因为Maven中央仓库的存在,当Maven在本地仓库找不到需要的jar文件时,它会查找远程仓库,而一个原始的Maven安装就自带了一个远程仓库——Maven中央仓库。
这个Maven中央仓库是在哪里定义的呢?在我的机器上,我安装了maven-2.0.10,我可以找到这个文件:${M2_HOME}/lib/maven-2.0.10-uber.jar ,
但是到了3.xxx版本之后在: maven安装目录下的:/lib/maven-model-builder-${version}.jar中
打开该文件,能找到超级POM:\org\apache\maven\model\pom-4.0.0.xml ,它是所有Maven POM的父POM,所有Maven项目继承该配置,你可以在这个POM中发现如下配置:
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
关于远程仓库的配置,下面的我会详细解释,这里我们只要知道,中央仓库的id为central,远程url地址为http://repo.maven.apache.org/maven2,它关闭了snapshot版本构件下载的支持。
在POM中配置远程仓库
前面我们看到超级POM配置了ID为central的远程仓库,我们可以在POM中配置其它的远程仓库。这样做的原因有很多,比如你有一个局域网的远程仓库,使用该仓库能大大提高下载速度,继而提高构建速度,也有可能你依赖的一个jar在central中找不到,它只存在于某个特定的公共仓库,这样你也不得不添加那个远程仓库的配置。
这里我配置一个远程仓库指向中央仓库的中国镜像:
<project>
...
<repositories>
<repository>
<id>maven-net-cn</id>
<name>Maven China Mirror</name>
<url>http://maven.net.cn/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-net-cn</id>
<name>Maven China Mirror</name>
<url>http://maven.net.cn/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
...
</project>
我们先看一下的配置,你可以在它下面添加多个 ,每个都有它唯一的ID,一个描述性的name,以及最重要的,远程仓库的url。此外,true告诉Maven可以从这个仓库下载releases版本的构件,而false告诉Maven不要从这个仓库下载snapshot版本的构件。禁止从公共仓库下载snapshot构件是推荐的做法,因为这些构件不稳定,且不受你控制,你应该避免使用。当然,如果你想使用局域网内组织内部的仓库,你可以激活snapshot的支持。
关于的更详细的配置及相关解释,请参考:http://www.sonatype.com/books/maven-book/reference_zh/apas02s08.html。
至于,这是配置Maven从什么地方下载插件构件(Maven的所有实际行为都由其插件完成)。该元素的内部配置和完全一样,不再解释。
在settings.xml中配置远程仓库
我们知道了如何在POM中配置远程仓库,但考虑这样的情况:在一个公司内部,同时进行这3个项目,而且以后随着这几个项目的结束,越来越多的项目会开始;同时,公司内部建立一个Maven仓库。我们统一为所有这些项目配置该仓库,于是不得不为每个项目提供同样的配置。问题出现了,这是重复 !
其实我们可以做到只配置一次,在哪里配置呢?就是settings.xml。
不过事情没有那么简单,不是简单的将POM中的及元素复制到settings.xml中就可以,setting.xml不直接支持 这两个元素。但我们还是有一个并不复杂的解决方案,就是利用profile,如下:
<settings>
...
<profiles>
<profile>
<id>dev</id>
<!-- repositories and pluginRepositories here-->
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
...
</settings>
这里我们定义一个id为dev的profile,将所有repositories以及pluginRepositories元素放到这个profile中,然后,使用元素自动激活该profile。这样,你就不用再为每个POM重复配置仓库。
使用profile为settings.xml添加仓库提供了一种用户全局范围的仓库配置。
使用镜像
如果你的地理位置附近有一个速度更快的central镜像,或者你想覆盖central仓库配置,或者你想为所有POM使用唯一的一个远程仓库(这个远程仓库代理的所有必要的其它仓库),你可以使用settings.xml中的mirror配置。
以下的mirror配置用maven.net.cn覆盖了Maven自带的central:
<settings>
...
<mirrors>
<mirror>
<id>maven-net-cn</id>
<name>Maven China Mirror</name>
<url>http://maven.net.cn/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
...
</settings>
这里唯一需要解释的是,这里我们配置central的镜像,我们也可以配置一个所有仓库的镜像,以保证该镜像是Maven唯一使用的仓库:
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
-->
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>Nexus Mirror</name>
<url>http://xx.xx/nexus/content/groups/public</url>
</mirror>
</mirrors>
<settings>
...
<mirrors>
<mirror>
<id>my-org-repo</id>
<name>Repository in My Orgnization</name>
<url>http://192.168.1.100/maven2</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
Maven最佳实践:Maven仓库 http://juvenshun.iteye.com/blog/359256
maven的配置文件为settings.xml,在下面路径中可以找到这个文件,分别为:
------ $M2_HOME/conf/settings.xml:全局设置,在maven的安装目录下;
------ ${user.home}/.m2/settings.xml:用户设置,需要用户手动添加,可以将安装目录下的settings.xml文件拷贝过来修改。
两个文件的关系为:如果两个文件同时存在,文件内容将被融合,相同设置将以用户设置的settings.xml为准。
该文件一共有10个配置项,文件结构为:
<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/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
下面对每一个配置项做一个简要的讲解,帮助理解每一项的含义和配置方式,以便后面做更深入的学习:
简单属性
<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>
<interactiveMode>true</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<offline>false</offline>
...
</settings>
localRepository:本地仓库路径,默认值
u
s
e
r
.
h
o
m
e
/
.
m
2
/
r
e
p
o
s
i
t
o
r
y
;
i
n
t
e
r
a
c
t
i
v
e
M
o
d
e
:
值
为
t
r
u
e
/
f
a
l
s
e
,
t
r
u
e
表
示
m
a
v
e
可
以
使
用
用
户
输
入
,
默
认
t
r
u
e
;
u
s
e
P
l
u
g
i
n
R
e
g
i
s
t
r
y
:
值
为
t
r
u
e
/
f
a
l
s
e
,
t
r
u
e
表
示
m
a
v
e
n
使
用
{user.home}/.m2/repository; interactiveMode:值为true/false,true表示mave可以使用用户输入,默认true; usePluginRegistry:值为true/false,true表示maven使用
user.home/.m2/repository;interactiveMode:值为true/false,true表示mave可以使用用户输入,默认true;usePluginRegistry:值为true/false,true表示maven使用{user.home}/.m2/plugin-registry.xml管理插件版本,默认为false;
offline:值为true/false,true表示构建系统在离线模式下执行,默认为false;
pluginGroups
每个pluginGroup元素都包含一个groupId,当你在命令行中没有提供插件的groupid时,将会使用该列表。这个列表自动包含org.apache.maven.plugins和org.codehaus.mojo。
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
例如:在做了上面的配置后,直接执行如下简写形式的命令即可
mvn jetty:run
servers
POM中的repositories和distributionManagement元素为下载和部署定义的仓库。一些设置如服务器的用户名和密码不应该和pom.xml一起分发。这种类型的信息应该存在于构建服务器上的settings.xml文件中。
<servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${user.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server>
</servers>
id:服务器的id,和repository/mirror中配置的id项匹配;
username,password:服务器的认证信息;
privateKey,passphrase:指定一个路径到一个私有key(默认为${user.home}/.ssh/id_dsa)和一个passphrase;
filePermissions,directoryPermissions:设置文件和文件夹访问权限,对应unix文件权限值,如:664,后者775.
注意:如果你使用一个已有key登录服务器,你必须忽略项,否则,key将会被忽略。
Mirrors
<mirrors>
<mirror>
<id>planetmirror.com</id>
<name>PlanetMirror Australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
id,name:镜像的唯一标识和用户友好的名称;
url:镜像的url,用于代替原始仓库的url;
mirrorof:使用镜像的仓库的id,可以使用下面匹配属性:
------:匹配所有仓库id;
------external::匹配所有仓库id,除了那些使用localhost或者基于仓库的文件的仓库;
------多个仓库id之间用逗号分隔;
------!repol:表示匹配所有仓库,除了repol。
注意:如果配置了多个仓库,首先匹配id精确匹配的镜像,否则maven使用第一个匹配的镜像。
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>
id:可选,为代理服务器设置一个名称;
active:true/false,默认true;
protocol:代理服务器使用的协议类型;
username:用户名;
password:密码;
host:主机名,或者ip;
port:端口号;
nonProxyHosts:不使用代理服务器的主机类型,多个主机之间用’|'分隔,可使用通配符,如:*.somewhere.com。
profiles
这里的profile元素是pom.xml的profile元素的一个裁剪版本,它包含activation、repositories、pluginRepositories和properties元素。
如果一个在settins中的profile是激活的,它的值将覆盖在一个POM或者profiles.xml文件中的任何相同id的profiles。
Activation
通过Activation来指定profile生效的环境,具体见下:
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>mavenVersion</name>
<value>2.0.3</value>
</property>
<file>
<exists>${basedir}/file2.properties</exists>
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
...
</profile>
</profiles>
activeByDefault:是否自动激活;
jdk:jdk版本,必须达到该版本后才能执行激活;
os:操作系统环境信息;
property:当maven探测到一个name=value值对时,profile才被激活;
file:文件exists或者missing可以激活该profile。
Properties
properties中的值可以在一个POM中通过
x
来
使
用
,
x
比
哦
是
一
个
p
r
o
p
e
r
t
y
,
以
下
形
式
在
s
e
t
t
i
o
n
g
s
.
x
m
l
文
件
中
都
可
以
使
用
:
−
−
e
n
v
.
X
;
表
示
使
用
一
个
环
境
变
量
,
如
:
{x}来使用,x比哦是一个property,以下形式在settiongs.xml文件中都可以使用: --env.X;表示使用一个环境变量,如:
x来使用,x比哦是一个property,以下形式在settiongs.xml文件中都可以使用:−−env.X;表示使用一个环境变量,如:{env.PATH}表示使用PATH环境变量;
–project.x:标识在POM中的对应元素的值,如:1.0可以通过
p
r
o
j
e
c
t
.
v
e
r
s
i
o
n
引
用
;
−
−
s
e
t
t
i
n
g
s
.
x
:
在
s
e
t
t
i
n
s
.
x
m
l
中
包
含
的
对
应
元
素
的
值
,
如
:
<
s
e
t
t
i
n
g
s
>
<
o
f
f
l
i
n
e
>
f
a
l
s
e
<
/
o
f
f
l
i
n
e
>
<
/
s
e
t
t
i
n
g
s
>
可
以
通
过
{project.version}引用; --settings.x:在settins.xml中包含的对应元素的值,如:<settings><offline>false</offline></settings>可以通过
project.version引用;−−settings.x:在settins.xml中包含的对应元素的值,如:<settings><offline>false</offline></settings>可以通过{settings.offline}引用;
–Java System Properties:所有java.lang.System.getProperties()获取的属性都是可用的,如:
j
a
v
a
.
h
o
m
e
;
−
−
x
:
在
<
p
r
o
p
e
r
t
i
e
s
/
>
中
或
者
一
个
扩
展
文
件
中
设
置
的
属
性
,
如
:
{java.home}; --x:在<properties/> 中或者一个扩展文件中设置的属性,如:
java.home;−−x:在<properties/>中或者一个扩展文件中设置的属性,如:{someVar};
配置方式为:
Repositories
仓库。仓库是Maven用来填充构建系统本地仓库所使用的一组远程项目。而Maven是从本地仓库中使用其插件和依赖。不同的远程仓库可能含有不同的项目,而在某个激活的profile下,可能定义了一些仓库来搜索需要的发布版或快照版构件。
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
releases、snapshots:不同的版本策略,对应发布版本和快照版本;
enabled:true/false,对应类型是否激活;
updatePolicy:更新策略,maven将比较本地POM的时间戳(存储在仓库的maven-metadata文件中)和远端的,配置选项可以设置:always、daily(一天一次,默认),interval:x(x为一整数,单位分钟),never;
checksumPolicy:maven部署文件到仓库时,也会部署对应的校验和文件,你可以设置:ignore,fail或者warn用于当校验和文件不存在或者检验失败时的处理策略;
layout:上面提到的仓库大部分都遵循共同的布局,可以配置:default(默认)或者legacy(遗留);
pluginRepositories
插件仓库。仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储大部分构件类型。另外一种构件类型是插件。Maven插件是一种特殊类型的构件。由于这个原因,插件仓库独立于其它仓库。pluginRepositories元素的结构和repositories元素的结构类似。每个pluginRepository元素指定一个Maven可以用来寻找新插件的远程地址。
activeProfiles
env-test
activeProfile中间定义activeProfile的id,在这里定义的activeProfile总是被激活,不关心环境设置,如果配置的id的profile没有发现,将没有任何事发生。
settings.xml 示例:
<?xml version="1.0" encoding="UTF-8"?>
<!--
| 官方文档: https://maven.apache.org/settings.html
|
| Maven 提供以下两种 level 的配置:
|
| 1. User Level. 当前用户独享的配置, 通常在 ${user.home}/.m2/settings.xml 目录下。
| 可在 CLI 命令行中通过以下参数设置: -s /path/to/user/settings.xml
|
| 2. Global Level. 同一台计算机上的所有 Maven 用户共享的全局配置。 通常在${maven.home}/conf/settings.xml目录下。
| 可在 CLI 命令行中通过以下参数设置: -gs /path/to/global/settings.xml
|
| 备注: User Level 优先级 > Global Level
|-->
<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">
<!--
| Maven 依赖搜索顺序, 当我们执行 Maven 命令时, Maven 开始按照以下顺序查找依赖的库:
|
| 步骤 1 - 在本地仓库中搜索, 如果找不到, 执行步骤 2, 如果找到了则执行其他操作。
| 步骤 2 - 在中央仓库中搜索, 如果找不到, 并且有一个或多个远程仓库已经设置, 则执行步骤 4, 如果找到了则下载到本地仓库中已被将来引用。
| 步骤 3 - 如果远程仓库没有被设置, Maven 将简单的停滞处理并抛出错误(无法找到依赖的文件)。
| 步骤 4 - 在一个或多个远程仓库中搜索依赖的文件, 如果找到则下载到本地仓库已被将来引用, 否则 Maven 将停止处理并抛出错误(无法找到依赖的文件)。
|-->
<!-- 地仓库路径, 默认值: ${user.home}/.m2/repository -->
<localRepository>${user.home}/workspace/env/maven/repository</localRepository>
<!-- 当 maven 需要输入值的时候, 是否交由用户输入, 默认为true;false 情况下 maven 将根据使用配置信息进行填充 -->
<interactiveMode>true</interactiveMode>
<!-- 是否支持联网进行 artifact 下载、 部署等操作, 默认: false -->
<offline>false</offline>
<!--
| 搜索插件时, 如果 groupId 没有显式提供时, 则以此处配置的 groupId 为默认值, 可以简单理解为默认导入这些 groupId 下的所有 artifact(需要时才下载)
| 默认情况下该列表包含了 org.apache.maven.plugins和org.codehaus.mojo
|
| 查看插件信息:
| mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin:3.5.1 -Ddetail
|-->
<pluginGroups>
<!-- plugin 的 groupId -->
<!--
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<!-- 进行远程服务器访问时所需的授权配置信息。通过系统唯一的 server-id 进行唯一关联 -->
<servers>
<server>
<!-- 这是 server 的 id, 该 id 与 distributionManagement 中 repository 元素的id 相匹配 -->
<id>server_id</id>
<!-- 鉴权用户名 -->
<username>auth_username</username>
<!-- 鉴权密码 -->
<password>auth_pwd</password>
<!-- 鉴权时使用的私钥位置。和前两个元素类似, 私钥位置和私钥密码指定了一个私钥的路径(默认是/home/hudson/.ssh/id_dsa)以及如果需要的话, 一个密钥 -->
<privateKey>path/to/private_key</privateKey>
<!-- 鉴权时使用的私钥密码, 非必要, 非必要时留空 -->
<passphrase>some_passphrase</passphrase>
<!--
| 文件被创建时的权限。如果在部署的时候会创建一个仓库文件或者目录, 这时候就可以使用权限(permission)
| 这两个元素合法的值是一个三位数字, 其对应了unix文件系统的权限, 如664, 或者775
|-->
<filePermissions>664</filePermissions>
<!-- 目录被创建时的权限 -->
<directoryPermissions>775</directoryPermissions>
<!-- 传输层额外的配置项 -->
<configuration></configuration>
</server>
</servers>
<!--
| 从远程仓库才下载 artifacts 时, 用于替代指定远程仓库的镜像服务器配置;
|
| 例如当您无法连接上国外的仓库是, 可以指定连接到国内的镜像服务器;
|
| pom.xml 和 setting.xml 中配置的仓库和镜像优先级关系(mirror 优先级高于 repository):
|
| repository(setting.xml) < repository(pom.xml) < mirror(setting.xml)
|
| 例如, 如果配置了 mirrorOf = *, 则 不管项目的 pom.xml 配置了什么仓库, 最终都会被镜像到 镜像仓库
|
| 私服的配置推荐用profile配置而不是mirror
|-->
<mirrors>
<!--
| 【mirro 匹配顺序】:
| 多个 mirror 优先级 按照 id字母顺序进行排列(即与编写的顺序无关)
| 在第一个 mirror 找不到 artifact, 不会继续超找下一个镜像。
| 只有当 mirror 无法链接的时候, 才会尝试链接下一个镜像, 类似容灾备份。
|-->
<!-- 上海交通大学反向代理 -->
<mirror>
<!-- 该镜像的唯一标识符, id用来区分不同的 mirror 元素, 同时会套用使用 server 中 id 相同授权配置链接到镜像 -->
<id>sjtugmaven</id>
<!-- 镜像名称, 无特殊作用, 可视为简述 -->
<name>sjtug maven proxy</name>
<!-- 镜像地址 -->
<url>https://mirrors.sjtug.sjtu.edu.cn/maven-central/</url>
<!-- 被镜像的服务器的id, 必须与 repository 节点设置的 ID 一致。但是 This must not match the mirror id
| mirrorOf 的配置语法:
| * = 匹配所有远程仓库。 这样所有 pom 中定义的仓库都不生效
| external:* = 匹配除 localhost、使用 file:// 协议外的所有远程仓库
| repo1,repo2 = 匹配仓库 repo1 和 repo2
| *,!repo1 = 匹配所有远程仓库, repo1 除外
|-->
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<!-- 用来配置不同的代理, 多代理 profiles 可以应对笔记本或移动设备的工作环境: 通过简单的设置 profile id 就可以很容易的更换整个代理配置 -->
<proxies>
<!-- 代理元素包含配置代理时需要的信息 -->
<proxy>
<!-- 代理的唯一定义符, 用来区分不同的代理元素 -->
<id>example_proxy</id>
<!-- 该代理是否是激活的那个。true则激活代理。当我们声明了一组代理, 而某个时候只需要激活一个代理的时候, 该元素就可以派上用处 -->
<active>false</active>
<!-- 代理的协议 -->
<protocol>https</protocol>
<!-- 代理的主机名 -->
<host>proxy.molo.com</host>
<!-- 代理的端口 -->
<port>443</port>
<!-- 代理服务器认证的登录名 -->
<username>proxy_user</username>
<!-- 代理服务器认证登录密码 -->
<password>proxy_pwd</password>
<!-- 不该被代理的主机名列表。该列表的分隔符由代理服务器指定;例子中使用了竖线分隔符, 使用逗号分隔也很常见 -->
<nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
</proxy>
</proxies>
<!--
| 构建方法的配置清单, maven 将根据不同环境参数来使用这些构建配置。
| settings.xml 中的 profile 元素是 pom.xml 中 profile 元素的裁剪版本。
| settings.xml 负责的是整体的构建过程, pom.xml 负责单独的项目对象构建过程。
| settings.xml 只包含了id, activation, repositories, pluginRepositories 和 properties 元素。
|
| 如果 settings 中的 profile 被激活, 它的值会覆盖任何其它定义在 pom.xml 中或 profile.xml 中的相同 id 的 profile。
|
| 查看当前激活的 profile:
| mvn help:active-profiles
|-->
<profiles>
<profile>
<!-- 该配置的唯一标识符 -->
<id>profile_id</id>
<!--
| profile 的激活条件配置;
| 其他激活方式:
| 1. 通过 settings.xml 文件中的 activeProfile 元素进行指定激活。
| 2. 在命令行, 使用-P标记和逗号分隔的列表来显式的激活, 如: mvn clean package -P myProfile)。
|-->
<activation>
<!-- 是否默认激活 -->
<activeByDefault>false</activeByDefault>
<!-- 内建的 java 版本检测, 匹配规则: https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html -->
<jdk>9.9</jdk>
<!-- 内建操作系统属性检测, 配置规则: https://maven.apache.org/enforcer/enforcer-rules/requireOS.html -->
<os>
<!-- 操作系统 -->
<name>Windows XP</name>
<!-- 操作系统家族 -->
<family>Windows</family>
<!-- 操作系统 -->
<arch>x86</arch>
<!-- 操作系统版本 -->
<version>5.1.2600</version>
</os>
<!--
| 如果Maven检测到某一个属性(其值可以在POM中通过${名称}引用), 并且其拥有对应的名称和值, Profile就会被激活。
| 如果值字段是空的, 那么存在属性名称字段就会激活profile, 否则按区分大小写方式匹配属性值字段
|-->
<property>
<!-- 属性名 -->
<name>mavenVersion</name>
<!-- 属性值 -->
<value>2.0.3</value>
</property>
<!-- 根据文件存在/不存在激活profile -->
<file>
<!-- 如果指定的文件存在, 则激活profile -->
<exists>/path/to/active_on_exists</exists>
<!-- 如果指定的文件不存在, 则激活profile -->
<missing>/path/to/active_on_missing</missing>
</file>
</activation>
<!-- 扩展属性设置。扩展属性可以在 POM 中的任何地方通过 ${扩展属性名} 进行引用
|
| 属性引用方式(包括扩展属性, 共 5 种属性可以引用):
|
| env.x : 引用 shell 环境变量, 例如, "env.PATH"指代了 $path 环境变量(在 Linux / Windows 上是 %PATH% ).
| project.x : 引用 pom.xml(根元素就是 project) 中 xml 元素内容.例如 ${project.artifactId} 可以获取 pom.xml 中设置的 <artifactId /> 元素的内容
| settings.x : 引用 setting.xml(根元素就是 setting) 中 xml 元素内容, 例如 ${settings.offline}
| Java System Properties : 所有可通过 java.lang.System.getProperties() 访问的属性都能在通过 ${property_name} 访问, 例如 ${java.home}
| x : 在 <properties/> 或者 外部文件 中设置的属性, 都可以 ${someVar} 的形式使用
|
|-->
<properties>
<!-- 在当前 profile 被激活时, ${profile.property} 就可以被访问到了 -->
<profile.property>this.property.is.accessible.when.current.profile.actived</profile.property>
</properties>
<!-- 远程仓库列表 -->
<repositories>
<!--
| releases vs snapshots
| maven 针对 releases、snapshots 有不同的处理策略, POM 就可以在每个单独的仓库中, 为每种类型的 artifact 采取不同的策略
| 例如:
| 开发环境 使用 snapshots 模式实时获取最新的快照版本进行构建
| 生成环境 使用 releases 模式获取稳定版本进行构建
| 参见repositories/repository/releases元素
|-->
<!--
| 依赖包不更新问题:
| 1. Maven 在下载依赖失败后会生成一个.lastUpdated 为后缀的文件。如果这个文件存在, 那么即使换一个有资源的仓库后, Maven依然不会去下载新资源。
| 可以通过 -U 参数进行强制更新、手动删除 .lastUpdated 文件:
| find . -type f -name "*.lastUpdated" -exec echo {}" found and deleted" \; -exec rm -f {} \;
|
| 2. updatePolicy 设置更新频率不对, 导致没有触发 maven 检查本地 artifact 与远程 artifact 是否一致
|-->
<repository>
<!-- 远程仓库唯一标识 -->
<id>maven_repository_id</id>
<!-- 远程仓库名称 -->
<name>maven_repository_name</name>
<!-- 远程仓库URL, 按protocol://hostname/path形式 -->
<url>http://host/maven</url>
<!--
| 用于定位和排序 artifact 的仓库布局类型-可以是 default(默认)或者 legacy(遗留)
| Maven 2为其仓库提供了一个默认的布局;然而, Maven 1.x有一种不同的布局。我们可以使用该元素指定布局是default(默认)还是legacy(遗留)
| -->
<layout>default</layout>
<!-- 如何处理远程仓库里发布版本的下载 -->
<releases>
<!-- 是否允许该仓库为 artifact 提供 发布版 / 快照版 下载功能 -->
<enabled>false</enabled>
<!--
| 每次执行构建命令时, Maven 会比较本地 POM 和远程 POM 的时间戳, 该元素指定比较的频率。
| 有效选项是:
| always(每次构建都检查), daily(默认, 距上次构建检查时间超过一天), interval: x(距上次构建检查超过 x 分钟)、 never(从不)
|
| 重要:
| 设置为 daily, 如果 artifact 一天更新了几次, 在一天之内进行构建, 也不会从仓库中重新获取最新版本
|-->
<updatePolicy>always</updatePolicy>
<!-- 当 Maven 验证 artifact 校验文件失败时该怎么做: ignore(忽略), fail(失败), 或者warn(警告) -->
<checksumPolicy>warn</checksumPolicy>
</releases>
<!-- 如何处理远程仓库里快照版本的下载 -->
<snapshots>
<enabled />
<updatePolicy />
<checksumPolicy />
</snapshots>
</repository>
<!--
国内可用的 maven 仓库地址(updated @ 2019-02-08):
http://maven.aliyun.com/nexus/content/groups/public
http://maven.wso2.org/nexus/content/groups/public/
http://jcenter.bintray.com/
http://maven.springframework.org/release/
http://repository.jboss.com/maven2/
http://uk.maven.org/maven2/
http://repo1.maven.org/maven2/
http://maven.springframework.org/milestone
http://maven.jeecg.org/nexus/content/repositories/
http://repo.maven.apache.org/maven2
http://repo.spring.io/release/
http://repo.spring.io/snapshot/
http://mavensync.zkoss.org/maven2/
https://repository.apache.org/content/groups/public/
https://repository.jboss.org/nexus/content/repositories/releases/
-->
</repositories>
<!--
| maven 插件的远程仓库配置。maven 插件实际上是一种特殊类型的 artifact。
| 插件仓库独立于 artifact 仓库。pluginRepositories 元素的结构和 repositories 元素的结构类似。
|-->
<!--
<pluginRepositories>
<pluginRepository>
<releases>
<enabled />
<updatePolicy />
<checksumPolicy />
</releases>
<snapshots>
<enabled />
<updatePolicy />
<checksumPolicy />
</snapshots>
<id />
<name />
<url />
<layout />
</pluginRepository>
</pluginRepositories>
-->
</profile>
</profiles>
<!--
| 手动激活 profiles 的列表, 按照 profile 被应用的顺序定义 activeProfile
| 任何 activeProfile, 不论环境设置如何, 其对应的 profile 都会被激活, maven 会忽略无效(找不到)的 profile
|-->
<!--
<activeProfiles>
<activeProfile>not-exits-profile</activeProfile>
</activeProfiles>
-->
</settings>