即使激活了另一个配置文件,如何保持活动的Maven配置文件处于活动状态? [英] How to keep Maven profiles which are activeByDefault active even if another profile gets activated?

查看:96
本文介绍了即使激活了另一个配置文件,如何保持活动的Maven配置文件处于活动状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的pom.xml中有一个配置文件,除非被明确停用(-P!firstProfile),否则该配置文件应始终处于活动状态. 我通过使用activeByDefault标志解决了这个问题:

I have a profile in my pom.xml which should be always active unless it is explicitely deactivated (-P !firstProfile). I solved this by using the activeByDefault flag:

<profiles>
  <profile>
    <id>firstProfile</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    ...
  </profile>
</profiles>

现在在同一pom.xml中,我定义了第二个配置文件,只有在该配置文件确实被激活时,该配置文件才应处于活动状态(-P secondProfile). 因此,默认行为是:firstProfile处于活动状态,secondProfile处于非活动状态. 在其他情况下,除了第一个配置文件外,我还想激活第二个配置文件. 现在的问题是,如果我使用"-P secondProfile"进行操作,那么不幸的是firstProfile被停用. Maven文档指出:

Now in the same pom.xml I have a second profile defined this should only be active if the profile is really activated (-P secondProfile). So the default behaviour is: firstProfile active, secondProfile inactive. At some other point I would like to activated the second profile in addition to the first profile. Now the problem is that if I do that with "-P secondProfile" the firstProfile unfortunately gets deactivated. The Maven documentation states this:

... 此个人资料将自动为 对所有版本都有效,除非另一个 同一POM中的配置文件已激活 使用前述的一种 方法.所有活动的配置文件 默认情况下是自动 在POM中的配置文件时停用 在命令行上激活或 通过其激活配置. ...

... This profile will automatically be active for all builds unless another profile in the same POM is activated using one of the previously described methods. 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. ...

是否有可能使firstProfile始终保持活动状态(而不必在settings.xml中声明它)?

Is there somehow a possibility how to keep the firstProfile always active (without having to declare it in the settings.xml)?

推荐答案

一个窍门是避免使用activeByDefault,而是通过缺少属性来激活配置文件,例如:

One trick is to avoid activeByDefault, and instead activate the profile by the absence of a property, eg:

<profiles>
  <profile>
    <id>firstProfile</id>
    <activation>
      <property>
        <name>!skipFirstProfile</name>
      </property>
    </activation>
    ...
  </profile>
</profiles>

然后您应该可以使用-DskipFirstProfile停用配置文件 或使用-P !firstProfile,否则该配置文件将处于活动状态.

You should then be able to deactivate the profile with -DskipFirstProfile or with -P !firstProfile, but otherwise the profile will be active.

请参阅: Maven:完整参考,配置文件激活-由于缺少属性而激活

这篇关于即使激活了另一个配置文件,如何保持活动的Maven配置文件处于活动状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆