基于多个属性的Maven配置文件的激活 [英] Activation of maven profile based on multiple properties

查看:190
本文介绍了基于多个属性的Maven配置文件的激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个项目创建一个maven 2构建,并且想出了配置文件,因为必须针对不同的位置(例如柏林,巴黎,北极)和不同的环境(开发,生产)都创建该构建.这些是通过属性指定的.因此,对于北极",开发",我会这样做:

I am creating a maven 2 build for a project and I came up with profiles since the build has to be created for both different locations (say Berlin, Paris, North Pole) and different environment (Development, Production). Those are specified via properties. So for "North Pole" "DEV" I do:

-Dlocation=NorthPole -Denvironment=DEV

现在,我想基于这两个属性(而不只是其中之一)启用porfile.因此,我尝试了以下操作:

Now I would like to acivate my porfile based on both these properties, not just one. So I tried following:

<profiles>
  <profile>
    <id>NOrth Pole DEV</id>
    <activation>
      <property>
        <name>location</name>
        <value>NorthPole</value>
      </property>
      <property>
        <name>environment</name>
        <value>DEV</value>
      </property>
    </activation>
    ... <!-- Set some North Pole DEV specific stuff -->
  </profile>
</profiles>

这不起作用,行家希望最多看到 <property>元素.

This doesn't work, maven expect to see at most one <property> element there.

请注意,这些属性还有另一种用途,因此使它成为值NorthPole-DEV的单个属性locationEnv并不是我想要的.

Please note I have another use for the properties as well so making it single property locationEnvof value NorthPole-DEV isn't what I want to have.

那么,有没有什么方法或解决方法,或者其他如何基于属性组合来激活配置文件?

So is there any way or workaround or whatever else how to activate an profile based on combination of properties?

推荐答案

为什么不直接使用个人资料,例如:

why not using profile directly like:

<profiles>
   <profile>
    <id>north-pole</id>
    <activation>
      <activeByDefault>false</activeByDefault>
    </activation>
    ....
  </profile>
   <profile>
    <id>dev</id>
    <activation>
      <activeByDefault>false</activeByDefault>
    </activation>
    ....
  </profile>
</profiles>

现在您可以通过命令行激活配置文件.

Now you can activate the profiles by command line.

mvn -Pdev,north-pole ...

这篇关于基于多个属性的Maven配置文件的激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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