12

我有两个 Maven 配置文件 profile-A 和 profile-B。只有在“A”未激活时才应激活“B”。所以如果我打电话

mvn install

profile-B 被执行(但不是 profile-A)。但如果我打电话

mvn install -Pprofile-A

然后只执行配置文件 A(但不执行配置文件 B)。

任何提示我需要如何编写我的 pom.xml 来实现这一点?

我已经尝试过了,但它不起作用:

<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>
4

1 回答 1

11

我认为要使您的示例命令行按预期工作,您所需要的只是<activeByDefault>true</activeByDefault>配置文件 B。

http://maven.apache.org/guides/introduction/introduction-to-profiles.html状态:

当在命令行或通过其激活配置激活 POM 中的配置文件时,默认情况下处于活动状态的所有配置文件都会自动停用。

于 2011-09-08T07:51:02.580 回答