Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - activate profile based on project property

Hi I am trying to achieve something like this:

In a parent pom, I have

<profile>
  <activation>
    <property>
      <name>Compile</name>
      <value>${project.artifactId}</value>
    ...

so that if I run mvn -DCompile=mod1 install under the parent pom, it will only apply the profile settings to module 1, but not the others.

Similarly, if I have

<profile>
  <activation>
    <property>
      <name>Compile</name>
      <value>${project.packaging}</value>
    ...

then running mvn -DCompile=war install under the parent pom, it will only apply the profile settings to those to be packed as war but not jar nor pom.

I tried but it didnt work as expected. Did I miss anything? Please help.

P.S. no need to suggest workarounds as I am only interested on this method. Simply answer it is not possible with reason if thats the case. Thank you

like image 478
user1589188 Avatar asked Sep 19 '13 08:09

user1589188


1 Answers

It won't work since...

To begin with:

  • Profile activation works with system properties and not with Maven properties.

And why it would not work from the parent down to the children:

  • The properties in the parent POM are expanded before your child POM even comes in the picture.

Many have gone here before you and failed.

One might wonder what you are really trying to do. Are you building different artifacts from the same source project? Perhaps you need a few more Maven modules to take care of things.

like image 52
Sander Verhagen Avatar answered Nov 15 '22 19:11

Sander Verhagen