Question

In maven, once you define your modules in you pom.xml all profiles aggregate the modules defined in them: (relevant part only)

<project>
    <modules>
        <module>module1</module>
    </modules>
    <profiles>
         <profile>
             <id>pr1</id>
             <modules>
                 <moudule>module2</module>
             </modules>

If you perform a mvn clean it will pass the command to module1.

If you issue mvn clean -Ppr1 it will pass along to module1 and module2.

I wonder if in maven 3 it is possible to have a pom.xml with submodules and override this. I mean to execute a profile that instead of add their own modules to the build force those like:

<project>
    <!-- omitted -->
    <modules>
        <!-- modules -->
    </modules>
    <build>
        <!-- build -->
    </build>
    <profiles>
        <profile>
             <!-- This profile with no modules -->
        </profile>
    </profiles>
</project>

The requirement might sound silly, but I just want to know if there is a mechanism like in plugin configuration.

<configuration self.combine="override"

Regards!

ssedano

Was it helpful?

Solution

It's not possible. Profile configuration is always merged with main configuration, so you only can add modules in your case.

What you can do instead, however, is to create a some kind of "default" profile (by <activeByDefault>true</activeByDefault> in <activation> section) that is enabled when no other profiles are invoked and put your default modules' list there. Then, when no profile is specified on Maven build call, this "default" profile is used, but when you call explicitly at least one profile, it's not, so you can this way define modules' list from scratch.

OTHER TIPS

While the question is old, Google still ranks it highly, so it makes sense to add a new answer.

You can use the activation by absence of a property trick to achieve what you want.

<profiles>
        <!-- By default, include the modules -->
        <profile>
            <id>full-build</id>
            <activation>
                <!-- Activation by absence of a property. Run normally, without -Dfull-build -->
                <property>
                    <name>!skip-modules</name>
                </property>
            </activation>
            <modules>
                <module>module1</module>
                <module>module2</module>
                <module>module3</module>
            </modules>
        </profile>

        <!-- No-modules build -->
        <profile>
            <id>no-modules</id>
            <activation>
                <!-- Activation by a property. Run with -Dskip-modules to activate -->
                <property>
                    <name>skip-modules</name>
                </property>
            </activation>
            <modules>
            </modules>
        </profile>
    </profiles>

You can do things like this:

  <profiles>
    <profile>
      <id>run-xyz</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <modules>
        <module>www-ab</module>
        <module>www-cd</module>
      </modules>
    </profile>

    <profile>
      <id>run-its</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <modules>
        <module>www-db</module>
        <module>www-it</module>
      </modules>
    </profile>
  </profiles>

If you are talking about such things. But i would recommend to be very carefull about such things.

It's only the question how you set activeByDefault. With this it's possible to create more or less any combination.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top