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

查看:34
本文介绍了即使另一个配置文件被激活,如何保持 activeByDefault 的 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:完整参考, 配置文件激活 - 因缺少属性而激活

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

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