0

I have a parent/root POM that (1) aggregates child modules, and (2) declares a profile that is conditionally activated based on a property value. So:

<packaging>pom</packaging>
<modules>
    <module>moduleA</module>
    <module>moduleB</module>
    <module>moduleC</module>
</modules>
<profiles>
    <profile>
        <id>myProfile</id>
        <activation>
            <property>
                <name>animal</name>
                <value>cat</value>
            </property>
        </activation>
    </profile>
</profiles>

And in moduleA, I declare the same profile as the parent, and would like it to be activated when I build moduleA using the activation criteria from the parent (animal == cat). But that isn't working. So if this is moduleA's POM:

<properties>
    <shape>circle</shape>
</properties>
<profiles>
    <profile>
        <id>myProfile</id>
        <properties>
            <shape>square</shape>
        </properties>
    </profile>
</profiles>

And I build moduleA using mvn help:evaluate -Danimal=cat, evaluating ${shape} says its value is circle, not square as I'd expect. So it seems like the child profile is not activating when building using its parent's activation criteria.

Is there a way to do this? Do I really have to copy and paste the <activation> block from the parent into all its children modules, just so I can get the same behavior?

Matt
  • 23,363
  • 39
  • 111
  • 152

1 Answers1

0

Try repeating the activation criteria in moduleA. You shouldn't have to repeat other profile content from the parent, but the activation criteria need to match.

<profile>
    <id>myProfile</id>
    <activation>
        <property>
            <name>animal</name>
            <value>cat</value>
        </property>
    </activation>
</profile>

Generally trying to share profile config from one module to another is tricky. There are other questions:

user944849
  • 14,524
  • 2
  • 61
  • 83