Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

You can disable maven profiles that have runByDefault set to true from the command line like so:

mvn install -P !default

Note, this requires Maven version 2.0.10.

Just add a space after -P the sintax of the command is

mvn install -P x

And not like you are using

mvn install -Px

Take a look at Maven - Introduction to profiles

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