Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a module and its submodules using maven reactor?

Tags:

maven

I have a project with three levels of modules. Let's suppose it has the following organization ...

+-- maven-root
   +-- maven-module-1
   |   +-- maven-submodule-1-1
   |   +-- maven-submodule-1-2
   +-- maven-module-2
   |   +-- maven-submodule-2-1
   |   +-- maven-submodule-2-2
   +-- maven-module-3
       +-- maven-submodule-3-1
       +-- maven-submodule-3-2

Additionally, we have the following set of dependencies

  • maven-module-2 depends upon maven-module-1
  • maven-module-3 depends upon maven-module-3

In this structure, and supposing artifacts for maven-module-1 and its submodules are already available in local repository, is there a solution using maven reactor (as an example) to build only maven-module-2 and its submodules ?

I already know that, using maven reactor, if I do

mvn clean install -pl :maven-module-2 --also-make-dependant

It will build

  1. maven-module-2
  2. maven-submodule-2-1
  3. maven-submodule-2-2
  4. maven-module-3
  5. maven-submodule-3-1
  6. maven-submodule-3-2

as maven-module-3 have a dependency upon maven-module-2

And obviously, running

mvn clean install -pl :maven-module-2 --also-make

will only build maven-module-1 and maven-module-2.

So, how, using that project organization, can I build only maven-module-2 ?

like image 622
Riduidel Avatar asked Jan 08 '13 10:01

Riduidel


1 Answers

Using

mvn clean install -f maven-module-2 -N

will build only maven-module-2 and

mvn clean install -f maven-module-2

will build maven-module-2 and its children

Take care that -f is used to say to Maven to use another POM (or module directory and it takes the pom.xml in it) than the one in the current directory. Thus unlike -pl where maven considers all modules in your project and then build only a subpart of them, -f only build what is referenced by this project/module/pom. To do

mvn clean install -f maven-module-2

is exactly like

cd maven-module-2; mvn clean install
like image 156
Arnaud Héritier Avatar answered Oct 19 '22 14:10

Arnaud Héritier