上面定义的pom.xml定义了两个profile:不同的”env”参数值会激活不同的profile。当执行命令:
mvn -Denv=dev-2 integration-test
就会激活profile “appserverConfig-dev-2”
当执行命令:
mvn -Denv=dev integration-test
就会激活profile “appserverConfig-dev”
而当执行命令:
mvn -Denv=production integration-test
则运行失败,因为没有激活任何一个profile,因此无法解析${appserver.home}。
查看build time过程中使用了哪些Profiles
执行help plugin的active-profiles goal,使用命令:
mvn help:active-profiles
例子:
对于上面的例子,如果输入命令:
mvn help:active-profiles -Denv=dev
则输出的是:
The following profiles are active:
- appserverConfig-dev (source: pom)
如果有一个profile定义在settings.xml里并使用<activeProfile>激活,那么输入命令:
mvn help:active-profiles
则输出的是:
The following profiles are active:
- appserverConfig (source: settings.xml)
如果输入命令:
mvn help:active-profiles -P appserverConfig-dev
那么输出的是:
The following profiles are active:
- appserverConfig-dev (source: pom)
- appserverConfig (source: settings.xml)