从父配置文件激活子配置文件 [英] Activating a Child Profile from a Parent Profile
问题描述
我有以下父pom.xml
文件:
<profile>
<id>build_full</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>mymodule_interface</module>
<module>mymodule_switch</module>
<module>mymodule_switch_simulator</module>
<module>mymodule_switch_controller</module>
<module>mymodule_server</module>
</modules>
</profile>
,在我的孩子pom中,mymodule_server
,我有以下内容:
and in my child pom for mymodule_server
, I have the following:
<profile>
<id>subprofile</id>
<modules>
<module>...various modules...</module>
</modules>
</profile>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>...various modules...</module>
</modules>
</profile>
当我调用maven:mvn -P build_full
时,如何强制子模块(mymodule_server
)使用配置文件subprofile
而不是default
?
How, when I invoke maven: mvn -P build_full
, can I force the child module (mymodule_server
) to use profile subprofile
rather than default
?
推荐答案
否,您不能从父级配置文件激活子级配置文件.通常,您无法从其他任何配置文件中激活或停用任何配置文件(存在JIRA功能请求 MNG-3309 ).您可以做的是激活基于同一属性的两个配置文件.
No, you can't activate a child profile from a parent profile. More generally, you can't activate or deactivate any profile from any other profile (there is a JIRA feature-request MNG-3309). What you can do is activate two profiles based on the same property.
首先,使用默认情况下已激活的配置文件通常不是一个好主意.您想要的是根据某些条件(操作系统版本,系统属性...)激活配置文件.要解决您的问题,可以在存在某个系统属性的情况下激活build_full
配置文件,并确保在存在相同属性的情况下也激活subprofile
.
First of all, using a profile that is activated by default is generally not a good idea. What you want is to activate a profile based on some condition (OS version, system property...). To solve your problem, you can activate build_full
profile when a certain system property is present, and make sure that subprofile
is also activated when that same property is present.
以下是一个示例配置,其中,当fullBuild
系统属性设置为true
时,两个配置文件均被激活.因此,使用mvn -DfullBuild=true ...
调用Maven将同时激活两个配置文件.
A sample configuration would be the following, where both profiles are activated when the fullBuild
system property is set to true
. Invoking Maven with mvn -DfullBuild=true ...
will thus activate both profiles.
<profile>
<id>build_full</id>
<activation>
<property>
<name>fullBuild</name>
<value>true</value>
</property>
</activation>
<modules>
<module>mymodule_interface</module>
<module>mymodule_switch</module>
<module>mymodule_switch_simulator</module>
<module>mymodule_switch_controller</module>
<module>mymodule_server</module>
</modules>
</profile>
<profile>
<id>subprofile</id>
<activation>
<property>
<name>fullBuild</name>
<value>true</value>
</property>
</activation>
<modules>
<module>...various modules...</module>
</modules>
</profile>
这篇关于从父配置文件激活子配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!