Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven profile activation with multiple conditions

I'm working on getting the rpm-maven plugin setup in a project. In our staging and production environments, the build occurs on Red Hat boxes, but we have several Windows boxes that are used for development and testing so I wanted the RPM build process to be part of a profile that is only active on a box that has rpmbuild installed.

This was my first attempt at an activation condition:

<activation>   <os>     <family>unix</family>   </os>    <file>     <exists>/usr/bin/rpmbuild</exists>   </file> </activation> 

My initial testing only involved building on a Windows box and building on a CentOS box, and both gave me the results I expected. Later, the build broke on a Linux machine that didn't have rpmbuild available. It looks like having two conditions like this isn't supported. Is this the case? I realize I can probably just get rid of the <os/> element and get the results I want, but for future reference is there a better way to create profiles with multiple activation conditions?

like image 496
bhinks Avatar asked Jan 07 '11 18:01

bhinks


People also ask

How does profile work in Maven?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.


2 Answers

Maven <activation> block is a list of OR -- the profile will be activated as soon as the first criteria is met. So, it is less likely that your problem has a solution at least until this bug-report gets fixed https://issues.apache.org/jira/browse/MNG-4565


Update:

it's fixed in 3.2.2 now – sfussenegger (via comment)

like image 57
Nishant Avatar answered Sep 20 '22 07:09

Nishant


And worst you can mix condition of different type for example file, jdk and property as described here http://www.sonatype.com/books/mvnref-book/reference/profiles-sect-activation.html, but you can't even put two condition of same type, for example two properties

<activation>     <property>            <name>integrationTest</name>     </property>     <property>         <name>packaging</name>         <value>swf</value>     </property>  </activation> 

This won't work as only one <property> tag will be allowed. Associated JIRA : https://issues.apache.org/jira/browse/MNG-3328

And the bug described above is still open... 5 years it's just a shame !

like image 21
Gab Avatar answered Sep 21 '22 07:09

Gab