EN
Maven - build only selected modules (build dependencies)
8
points
In this short article, we would like to show how to build selected modules in a Maven project.
Simple steps:
- go to the parent project:
cd C:/project
- run the following command separating module names with commas:
mvn -pl module-1,module-2,module-3 -am clean install
Hint: modules will be built in provided order, it means:
module-1
,module-2
and as lastmodule-3
.
Practical example
In the below example we present how to build a Spring Boot Application that uses a common jar
module/project.
cd C:/projects/shop-application
mvn -pl common,shop -am clean install
Where: shop
module uses common
module as a dependency.
Example output:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] Example projects [pom]
[INFO] Common [jar]
[INFO] Shop [war]
[INFO]
[INFO] --------------------< com.example:com.example:com >---------------------
[INFO] Building Example projects 0.0.1-SNAPSHOT [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
...
...
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Example projects 0.0.1-SNAPSHOT:
[INFO]
[INFO] Example projects ................................... SUCCESS [ 0.215 s]
[INFO] Common ............................................. SUCCESS [ 3.003 s]
[INFO] Shop ............................................... SUCCESS [ 52.228 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.607 s
[INFO] Finished at: 2021-10-11T12:37:57+02:00
[INFO] ------------------------------------------------------------------------
Where Example projects
is the name of the parent project that contains common
and shop
modules.
Tests skipping
To skip tests add -Dmaven.test.skip=true
parameter:
mvn -pl common,shop -am clean install -Dmaven.test.skip=true