2

I would like to include a module via an included pom only if a certain property is not set.

So I define in my parent pom:

<profiles>
    <profile>
        <id>aggregator</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <aggregator>aggregator</aggregator>
        </properties>
        </profile>
 </profiles>

In one of the sub-modules, I would like to activate another profile, if the property is not set:

<profiles>
    <profile>
        <id>incubation</id>
        <activation>
           <property>
                <name>!aggregator</name>
            </property>
        </activation>
        <modules>
            <module>../../examples/org.eclipse.nebula.examples</module>
            <module>../../examples/org.eclipse.nebula.examples.feature</module>
        </modules>
    </profile>
 </profiles>

AFAICS this is how https://maven.apache.org/guides/introduction/introduction-to-profiles.html describes it.

But the example modules are still included. What is wrong with this setup?

vogella
  • 24,574
  • 4
  • 29
  • 26
  • Do you activate any other profiles on command line? This would deactivate the `aggregator` profile. Furthermore, I think you cannot use properties from the POM itself to activate/deactivate profiles. They are probably not resolved before the profiles are evaluated by Maven. – J Fabian Meier Nov 04 '21 at 09:40
  • First I would ask why would you like to include modules based on profiles which is in general a bad idea... – khmarbaise Nov 04 '21 at 10:38
  • Agree with @khmarbaise - I would go so far as to call inclusion of modules with profile an anti-pattern. And as @jfabianmeier notes `activeByDefault` does not mean "always active" - it means "active if no other profile in the same POM is active." ([Maven doc](https://maven.apache.org/guides/introduction/introduction-to-profiles.html)). – user944849 Nov 04 '21 at 13:23
  • The build allows to build the second parent separately. So in the main pom is used, certain artifacts are included twice which fails the build. So I need to excluded it. – vogella Nov 04 '21 at 13:47
  • Hm...that sounds like an issue in general... The aggregator looks like including an OSGi feature ? I don't see things like a parent? Do you have a reference link to the project? – khmarbaise Nov 04 '21 at 14:00
  • @khmarbaise https://github.com/eclipse/nebula – vogella Nov 04 '21 at 14:06
  • Isn't the issue here that PropertyProfileActivation doesn't work for pom defined properties? https://maven.apache.org/pom.html#Activation – Robert Scholte Nov 04 '21 at 15:24
  • 1
    Indeed, @RobertScholte, I didn't look closely enough the first time. I've answered this [before](https://stackoverflow.com/a/23496528/944849) after my own struggles trying to make it work. – user944849 Nov 04 '21 at 15:59
  • How do you run the build from the command line when you'd like the desired thing to happen? (I specified from the command line because, IIRC, disabling a profile like that from an M2E launch from Eclipse does not work, so it's better to first check that from the command line). In any case, do not expect the property `aggregator` defined inside the `aggregator` profile to be taken into consideration when Maven detects which profiles to activate, it does not work like that. – lorenzo-bettini Nov 05 '21 at 14:33

1 Answers1

0

I solved it differently. Only use a profile in the top-level pom and only include a part of the modules based on that profile.

vogella
  • 24,574
  • 4
  • 29
  • 26