Maven multi module projects
A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom.
Now, the submodules are regular Maven projects, and they can be built separately or through the aggregator POM.
By building the project through the aggregator POM, each project that has a packaging type different than pom will result in a built archive file.
Parent POM
Hence, we can create our own pom.xml file which will serve us as the parent project. Then, we can include there all configurations with dependencies and set this as the parent of our child modules, so they'll inherit from it.
Besides the inheritance, Maven provides the notion of aggregation. Parent POM that leverages this functionality is called an aggregate POM. Basically, this kind of POM declares its modules explicitly in its pom.xml file.
Submodule
Creating parent pom
mvn archetype:generate -DgroupId=org.company -DartifactId=parent-project
<packaging>pom</packaging>
Creating submodule projects
navigate to the parent project directory
cd parent-project
mvn archetype:generate -DgroupId=org.company -DartifactId=core
mvn archetype:generate -DgroupId=org.company -DartifactId=service
mvn archetype:generate -DgroupId=org.company -DartifactId=webapp
Add below tag into parent pom
<modules>
<module>core</module>
<module>service</module>
<module>webapp</module>
</modules>
<parent>
<groupId>org.company</groupId>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
mvn package
Source: https://www.baeldung.com/
Comments
Post a Comment