How to activate Maven profile for a specific module in mutli-module project

We have a multi-module Maven project consisting of a parent POM and 5 or more modules.

Each module can be deployed to a running server as part of the assembly if we activate our custom “auto-deploy” profile, which is explicitly defined in each module, because how / what is deployed is slightly different for each of the modules.

When creating from the parent POM, although if I activate the "auto-deploy" profile, Maven will finish deploying all the modules, which almost never needs to be done (based on our dev process, etc.). But we want to build from the root, as there may be changes in several modules, and there are dependencies between some modules.

Is there a way, when you build from the parent POM, to activate our "automatic deployment" user profile for only one of the modules, but not for all?

thanks

+4
source share
2 answers

If each of your modules has its own "auto-deploy" profile, and profile activation is triggered by the variables passed to the mvn command, you can run the single mvn command in the parent module and decide which modules should be deployed simply by declaring the activation variables

 <profiles> <profile> <id>profileId</id> <activation> <property> <name>profileIdEnabled</name> <value>true</value> </property> </activation> <properties></properties> </profile> </profiles> 

and then

 mvn -DprofileIdEnabled=true 
+4
source

Check out Maven: full link - section 6.2. Using advanced reactor parameters .

Starting with Maven 2.1, there are new Maven command-line options that let you manipulate how Maven builds multi-module projects. These new options:

-rf, -resume-from

  Resume reactor from specified project 

-pl, --projects

  Build specified reactor projects instead of all projects 

-am, -also-make

  If project list is specified, also build projects required by the list 

-amd, -also-make-dependents

  If project list is specified, also build projects that depend on projects on the list 

To create only module-b from the root directory:

$ mvn --projects module-b install

+3
source

All Articles