Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using profiles to control which Maven modules are built

Tags:

maven

profiles

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.

like image 751
Galder Zamarreño Avatar asked Nov 14 '12 14:11

Galder Zamarreño


People also ask

Why profiles are used in Maven?

Profiles modify the POM at build time, and are used to give parameters different target environments (for example, the path of the database server in the development, testing, and production environments).

How do I run a specific profile in Maven?

What you should do is check the profile behavior by doing the following : set activeByDefault to true in the profile configuration, run mvn help:active-profiles (to make sure it is effectively activated even without -Pdev1 ), run mvn install .


1 Answers

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> 
like image 118
Galder Zamarreño Avatar answered Sep 23 '22 12:09

Galder Zamarreño