Maven:仅在未激活配置文件B的情况下才激活配置文件A? [英] Maven: Only activate profile A if profile B is not activated?
问题描述
我有两个Maven配置文件配置文件A和B.仅在未激活"A"的情况下才激活"B". 因此,如果我打电话给
I have two Maven profiles profile-A and profile-B. "B" should only be activated if "A" is not activated. So if I would call
mvn install
配置文件B被执行(但不执行配置文件A). 但是如果我打电话给
profile-B is executed (but not profile-A). But if I would call
mvn install -Pprofile-A
然后仅执行配置文件A(但不执行配置文件B).
then only profile-A is executed (but not profile-B).
有什么提示我需要编写pom.xml来实现这一目标吗?
Any hints how I need to write my pom.xml to achieve this?
我已经尝试过了,但是不起作用:
I already tried this, but it doesn't work:
<profiles>
<profile>
<id>profile-A</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
...
</profile>
<profile>
<id>profile-B</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!profile-A</name>
</property>
...
</activation>
...
</profile>
</profiles>
推荐答案
我想让您的示例命令行按预期工作,您只需要配置文件B的<activeByDefault>true</activeByDefault>
.
I think for your example command line to work as expected, all you need is the <activeByDefault>true</activeByDefault>
for profile B.
http://maven.apache.org/guides/introduction/Introduction-to-profiles.html 状态:
在命令行上或通过其激活配置激活POM中的配置文件时,默认情况下处于活动状态的所有配置文件都会自动停用.
All profiles that are active by default are automatically deactivated when a profile in the POM is activated on the command line or through its activation config.
这篇关于Maven:仅在未激活配置文件B的情况下才激活配置文件A?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!