Building a module with its dependencies in a multi module Maven project
This recipe shows you how to build a specific Maven module in a multi module Maven project. It may be useful to reduce the build time during development, and it’s particular useful when the project you are working has lots of modules and it takes long time to finish the build.
The trick here is to use Maven advanced reactor options, particularly the following options:
Build specified reactor projects instead of all projects
If project list is specified, also build projects required by the list
So, using the previous options, and assuming we have a multi module maven project A with submodules from A1 to A10, where we only want to build A3 with its own dependencies, we could simply go to the root of A and execute the following command:
$SHELL > mvn clean install -pl A3 -am
This recipes makes it possible to decrease the build time, thus leading to decreased development time too, which may be a good way to make the development faster and cheaper.
Similarly to the previously shown maven command, and assuming that, since our previous maven build, we had not changed anything in the “dependent” modules of A3 and we had only changed something in A3, we could also simply build module A3 without its dependents:
$SHELL > mvn clean install -pl A3