1

Using maven 3.1.1

In my parent pom I have:

    <groupId>com.samples</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>Parent</name>
    <modules>
        <module>a</module>
        <module>b</module>
        <module>c</module>
    </modules>

    <profiles>
        <profile>
            <id>skip-c</id>
            <modules>
                   <module>a</module>
                   <module>b</module>
                </modules>
        </profile>
...

But module c is still build with I build with:

mvn clean package -Pskip-c

How do I skip a submodule when building my parent project?

u123
  • 15,603
  • 58
  • 186
  • 303
  • maybe this can help you: http://stackoverflow.com/questions/8304110/skip-a-submodule-during-a-maven-build – julschi Mar 20 '14 at 13:30
  • not really since I need to remove a sub module not add one. That example adds the integration-test module which is skipped by default. I need my default to be as complete as possible. – u123 Mar 20 '14 at 13:37

3 Answers3

2

Your problem is that your complete module list is always active. You could use a default profile instead.

<groupId>com.samples</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent</name>

<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <modules>
            <module>a</module>
            <module>b</module>
            <module>c</module>
        </modules>
    </profile>
    <profile>
        <id>skip-c</id>
        <modules>
            <module>a</module>
            <module>b</module>
        </modules>
    </profile>
</profiles>
Steven Pessall
  • 983
  • 5
  • 15
0

In addition to julschis comment some details:

Profiles do not replace the normal non profile content of the pom. Therefore, when using your profile, you get a, b and c from the normal pom, and a and b from the profile, therefore your profile is useless.

You need to remove your conditional modules from the main part and put it only into profiles (usually an activeByDefault Profile).

<profile>
  <id>default</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
    <modules>
        <module>a</module>
        <module>b</module>
    </modules>
</profile>
<profile>
  <id>add-c</id>
    <modules>
        <module>a</module>
        <module>b</module>
        <module>c</module>
    </modules>
</profile>

So it is the other way around, profiles cannot remove anything, but only add or override content.

This technique is called reactor pruning and described here: http://www.blackbuild.com/how-to-really-use-maven-profiles-without-endangering-your-karma/

Your could also use the new functionality from https://jira.codehaus.org/browse/MNG-5230, and simply call (this requires Maven 3.2.1+)

mvn clean package -pl !c
blackbuild
  • 5,026
  • 1
  • 23
  • 35
0

Deactivation of profiles can be done using Maven 2.0.10 + .

http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Deactivating a profile

Starting with Maven 2.0.10, one or more profiles can be deactivated using the command line by prefixing their identifier with either the character '!' or '-' as shown below:

mvn groupId:artifactId:goal -P !profile-1,!profile-2

This can be used to deactivate profiles marked as activeByDefault or profiles that would otherwise be activated through their activation config.

Jyotsna Saroha
  • 678
  • 6
  • 13