【发布时间】:2015-02-26 00:54:55
【问题描述】:
我有以下情况:
parent.pom
<profiles>
<profile>
<id>P1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
whatever
</build>
</profile>
<profile>
<id>P2</id>
<activation>
<property>
<name>prop1</name>
</property>
</activation>
<build>
whatever
</build>
</profile>
有没有什么方法可以让子级上的“mvn clean install”激活配置文件 P2 而无需指定“mvn clean install -PP2”或“mvn clean install -Dprop1”之类的配置文件或更改 settings.xml?
prop1 不是配置或,它只是激活配置文件 P2 的配置。
我试过了:
child.pom
<properties>
<prop1>exists</prop1>
</properties>
但由于http://maven.apache.org/guides/introduction/introduction-to-profiles.html,它并没有像我预期的那样工作
那么,有没有人做过或需要类似的东西?
【问题讨论】:
-
您实际上是在描述无条件激活,在这种情况下,您应该将配置文件
P2的<activeByDefault>设置为true(然后将profilesP1和 @987654329 @ 默认为active)。 -
这种情况可以吗?默认激活 2 个配置文件?
-
而
<exists>和<missing>旨在用作驱动激活的条件,通常用于<file>s,尽管从Maven 2.0.9开始,这些可以被插值。支持的变量是${user.home}等系统属性和${env.HOME}等环境变量。 -
我必须说我没有尝试使用
<activeByDefault>激活 2 个配置文件。不过,我看不出有什么理由不应该支持它。 -
我做了一个快速测试并确认它有效 - 您可以拥有任意数量的个人资料
<activeByDefault>。但是,请阅读文档中有关此类配置文件的警告:“除非使用上述方法之一激活同一 POM 中的另一个配置文件,否则此配置文件将自动对所有构建处于活动状态。默认情况下处于活动状态的所有配置文件都会自动在命令行或通过其激活配置激活 POM 中的配置文件时停用。"
标签: maven properties profile defined