Skip to main content

How to create a Multi-Module Project in Maven

A multi-module project in Maven is built from an aggregator POM that manages a group of sub-modules.

In most cases, the aggregator is located in the project's root directory and must have packaging of type "pom".

Let's create a maven project "rabbit-mq-java" having two modules "producer" and "consumer".

mvn archetype:generate -DgroupId=com.codeburps -DartifactId=rabbit-mq-java -DinteractiveMode=false

Once the parent project is generated, we have to open the pom.xml file located in the parent's directory and add the packaging as "pom":

<packaging>pom</packaging>

The parent maven project is of packaging type "pom" and acts as an aggregator - it won't produce other artifacts.

cd rabbit-mq-java
mvn archetype:generate -DgroupId=com.codeburps -DartifactId=producer -DinteractiveMode=false
mvn archetype:generate -DgroupId=com.codeburps -DartifactId=consumer -DinteractiveMode=false

The information about all the submodules will be added in the parent-project's pom.xml:

    <modules>
        <module>producer</module>
        <module>consumer</module>
    </modules>

The information about the parent-project will be added in each of the submodules' pom.xml:

    <parent>
        <groupId>com.codeburps</groupId>
        <artifactId>rabbit-mq-java</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

In order to package, add the following properties in the parent-project's "pom.xml":

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

By building the project through the aggregator POM, each project that has a packaging type different from "pom" will result in a built archive file.

% mvn package

Child projects are independent maven projects but inherit properties from parent project.



Comments

Popular posts from this blog

Deploying Spring Boot microservices on Kubernetes Cluster

This article guides you through the deployment of two Spring Boot microservices, namely "order-service" and "inventory-service," on Kubernetes using "MiniKube" . We will establish communication between them, with "order-service" making calls to an endpoint in "inventory-service." Additionally, we will configure "order-service" to be accessible from the local machine's browser . 1) Create Spring Boot microservices The Spring Boot microservices, "order-service" and "inventory-service," have been developed and can be found in this GitHub repository. If you are interested in learning more about creating Spring Boot REST microservices, please refer to this or this (Reactive) link. 2) Build Docker Images The Docker images for both "order-service" and "inventory-service" have already been generated and deployed on DockerHub, as shown below. codeburps/order-service cod...

Circuit Breaker Pattern with Resilience4J in a Spring Boot Application

Read Also: Spring Cloud Circuit Breaker + Resilience4j Resilience4j is a lightweight fault tolerance library that draws inspiration from Netflix Hystrix but is specifically crafted for functional programming. The library offers higher-order functions, known as decorators , designed to augment any functional interface, lambda expression, or method reference with features such as Circuit Breaker, Rate Limiter, Retry, or Bulkhead . These functionalities can be seamlessly integrated within a project, class, or even applied to a single method. It's possible to layer multiple decorators on any functional interface, lambda expression, or method reference, allowing for versatile and customizable fault tolerance. While numerous annotation-based implementations exist online, this article focuses solely on the reactive approach using router predicates and router functions . How Circuit Breaker Pattern works? In general, a circuit breaker functions as an automatic electrical s...

How to create a basic Spring 6 project using Maven

Below is a step-by-step guide to creating a basic Spring project using Maven. 1) Create a Maven Project Use the following Maven command to create a new Maven project. mvn archetype:generate -DgroupId=com.tb -DartifactId=spring-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false 2) Import in IntelliJ IDEA If you haven't already, open IntelliJ IDEA on your system. Go to "File" > "New" > "Project from Existing Sources..." . In the file dialog, navigate to the directory where your Maven project is located. Select the pom.xml file within the project directory and click "Open." 3) Update pom.xml In total, the application requires the below-mentioned dependencies: 4) Create Spring Configuration Create a Java configuration class that uses annotations to define your Spring beans and their dependencies. This class should be annotated with @Configuration . 5) Create the Main Application C...