我能否让一个Maven配置文件激活另一个配置文件?

80

我有两个 Maven2 配置文件,分别是 selenium 和 jspc。现在,对于“selenium”,我希望能够隐式激活“jspc”,这样我就不用从命令行中编写“mvn -Pselenium,jspc”了。这种情况是否可能?

1个回答

100

你不能“链接”配置文件激活(Maven参考),但你可以通过相同的属性激活它们:

<activation>
  <property>
    <name>profile.selenium</name>
  </property>
</activation>

然后运行mvn -Dprofile.selenium


5
https://dev59.com/tXE95IYBdhLWcg3wlu6z#2248552 这里详细介绍了为什么你不能链接(chain)它。 - bradley.ayers
此外,您还可以根据属性的不存在定义激活 - 这使您能够创建互斥的配置文件(除非您强制激活两个)。例如: <profile> <id>test-default</id> <activation> <property> <name>!profile.externalAndContractTests</name> </property> </activation>... - RobertG
1
对于我的情况,我有profile1继承profile2继承profile3,所以上面的方法行不通,因为激活只能使用一个属性。相反,我只需使用maven-enforcer-pluginrequireProperty,并将mvn install -Dprofile1,profile2,profile3粘贴到requireProperty->message中。所以每次我只需要执行mvn install profile3,就会收到警告并复制输出消息再次运行。 - Ng Sek Long
@bradley.ayers 总是有人试图为什么辩护。我可以想到100种实现方法。只需寻找匹配的配置文件,将它们统一起来。 - mjs

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接