Using profiles to control which Maven modules are built

Galder Zamarreño picture Galder Zamarreño · Nov 14, 2012 · Viewed 33.1k times · Source

I have the following XML in my maven POM.xml:

<profiles>
  <profile>
     <id>default</id>
     <activation>
        <activeByDefault>true</activeByDefault>
        <property>
           <name>default</name>
           <value>!disabled</value>
        </property>
     </activation>
     <modules>
        <module>m1</module>
        <module>m2</module>
        <module>m3</module>
     </modules>
  </profile>
  <profile>
     <id>x</id>
     <modules>
        <module>m1</module>
     </modules>
  </profile>
</profiles>

What I'm trying to achieve is this:

  1. When I run mvn install, I want it to build m1, m2 and m3 projects.

  2. When I run mvn install -Px, I want it to only build m1.

My current problem is that with the code above, option 2 builds all m1, m2 and m3.

Answer

Galder Zamarre&#241;o picture Galder Zamarreño · Nov 14, 2012

Found the solution guys, define 'x' profile first and the 'default' and it works fine (insane Maven!!). Here's the final result:

   <profiles>
      <!-- DO NOT CHANGE THE *ORDER* IN WHICH THESE PROFILES ARE DEFINED! -->
      <profile>
         <id>x</id>
         <modules>
            <module>m1</module>
         </modules>
      </profile>
      <profile>
         <id>default</id>
         <activation>
            <activeByDefault>true</activeByDefault>
         </activation>
         <modules>
            <module>m1</module>
            <module>m2</module>
            <module>m3</module>
         </modules>
      </profile>
   </profiles>