当须要根据不一样的环境, 采用不一样的依赖库、配置、插件, 能够使用profiles. 配置要点是activation激活条件,在如下几种状况下,profile将被激活:html
查看profile是否被激活, 使用命令 mvn help:active-profiles
条件匹配规则:
###jdk
测试jdk版本是否匹配, 也能够限定一个范围, 例如 <jdk>(1.6, 1.8]</jdk> 限制jdk的版本为1.7, 1.8
版本号范围的语法, 见http://maven.apache.org/pom.html#Dependency_Version_Requirement_Specification
###os
操做系统是否匹配, 它又有4个子项, <arch><family><name><version>, 使用命令mvn -v能够查看当前操做系统的信息:java
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
当<os>下所列举出的条件都匹配时, <os>选项才算匹配
###property 判断java系统变量是否匹配, 包含-D定义的系统变量, 不包含在pom.xml中定义的properties, 也不包含环境变量.apache
<profiles> <profile> <activation> <property> <name>debug</name> <value></value> </property> </activation> </profile> </profiles>
若是value字段为空(没有可见字符), 则表示匹配任何值
###file
判断文件是否存在或者不存在, 它又有两个子项<exists>和<missing>. 这两个子项, 只能选其一, 若是这两个子项都存在, <missing>将被忽略; 文件路径只能填相对路径。例如windows
<profiles> <profile> <activation> <file> <exists>${basedir}/debug.properties</exists> </file> </activation> </profile> </profiles>
<file>标签不识别${project.basedir}, 应该属于这个版本的bug.maven