maven pom进阶教程 - profiles

当须要根据不一样的环境, 采用不一样的依赖库、配置、插件, 能够使用profiles. 配置要点是activation激活条件,在如下几种状况下,profile将被激活:html

  1. activeByDefault=true, 而且其它的profile都未被激活, 此时无视匹配条件, 保底做用, 保证一定有一个profile被激活
  2. activeByDefault=false, 而且activation下的全部条件都匹配, 若是activation下没有匹配条件, 则视为不匹配.
  3. mvn执行命令时, 加入-P <profileID>, 此时一定激活id为profileID的profile, 无视匹配条件

查看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

相关文章
相关标签/搜索