Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define conditional properties in maven?

Tags:

maven-2

maven

For instance, I would like to have property Configuration set to ${env:AAA} if there is an environment variable AAA and to some other constant value if there is no such environment variable.

How do I do it in maven 2?

like image 894
mark Avatar asked Jan 20 '13 22:01

mark


2 Answers

It appears as though you activate a profile conditionally...

<profiles>
  <profile>
    <activation>
      <property>
        <name>environment</name>
        <value>test</value>
      </property>
    </activation>
    ...
  </profile>
</profiles>

The profile will be activate when the environment variable is defined to the value test as in the following command:

mvn ... -Denvironment=test

like image 190
hd1 Avatar answered Oct 18 '22 13:10

hd1


On the off-chance that a system property is acceptable, you can simply define the property in your POM file and override when required:

<project>
...
  <properties>
     <foo.bar>hello</foo.bar>
  </properties>
...
</project>

You can reference this property elsewhere in your POM by referring to ${foo.bar}. To override on the command line, just pass a new value:

mvn -Dfoo.bar=goodbye ...
like image 24
Duncan Jones Avatar answered Oct 18 '22 12:10

Duncan Jones