2

I have two pom's an aggregate and a child, the child has a profile I would like to be activated based upon a property set in the parents profile eg.

parent pom.xml

<profiles>
    <profile>
        <id>emptyModules</id>

        <modules>
            <module>child</module>
        </modules>

        <properties>
            <emptyModules>true</emptyModules>
        </properties>
    </profile>
</profiles>

The child has two profiles one with some modules the other without

<profiles>
    <profile>
        <id>modules</id>

        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>

        <modules>
            <module>module1</module>
            <module>module2</module>
        </modules>
    </profile>
    <profile>
        <id>emptyModules</id>

        <activation>
            <property>
                <name>emptyModules</name>
                <value>true</value>
            </property>
        </activation>

    </profile>
</profiles>

When I activate the parent emptyModules profile I want the child emptyModule profile to activate, however the default profile is used instead! Any ideas?

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
PDStat
  • 5,513
  • 10
  • 51
  • 86
  • I don't think this is possible because profile activation happens at the very beginning of the build process. If I understand it correctly, it is done before any part of the pom is executed. – J Fabian Meier Oct 25 '17 at 09:34
  • What Maven command are you using when you "activate" the parent emptyModules profile? – Pierre B. Oct 25 '17 at 09:36
  • eg. `mvn clean install -PemptyModules` – PDStat Oct 25 '17 at 09:49
  • Never add/remove modules by profiles...[otherwise this will lead to problems](http://blog.soebes.de/blog/2013/11/09/why-is-it-bad-to-activate-slash-deactive-modules-by-profiles-in-maven/)...The question is why do you need this? What kind of problem are you trying to solve... – khmarbaise Oct 25 '17 at 10:19
  • Just for the sake of completeness, I made a small example of what you had and it worked for me `mvn clean install -P emptyModules` did only build the parent and the child without any submodules and `mvn clean install` was building everything. If you're interested in the code, just let me know. – funfried Oct 25 '17 at 11:13

1 Answers1

0

You can activate profiles based on properties:

<profiles>
  <profile>
    <activation>
      <property>
        <name>someprop</name>
      </property>
    </activation>
    ...
  </profile>
</profiles>

This could be used to activate a parent and child profile at once.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Isn't that exactly what I have above in the child pom profile – PDStat Oct 25 '17 at 09:49
  • Sorry, I did not read thorough enough. It don't think it is possible to do in your way, but you could set parameters on the command line and use in different profiles. – J Fabian Meier Oct 25 '17 at 09:51