Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
1.1.
Importance of Maven
1.2.
Features of Maven
2.
Maven Architecture
3.
Repository in Maven
4.
Maven Build Lifecycle
5.
Maven Phases
6.
Maven Goals
7.
Frequently Asked Questions
7.1.
How should one run the command to add JAR files to the local repository?
7.2.
What are Maven plugins used for? 
7.3.
In what locations are Maven dependencies kept?
7.4.
What is POM?
7.5.
What does a Maven snapshot mean?
8.
Conclusion 
Last Updated: Mar 27, 2024

Maven Architecture

Author Ayush Mishra
0 upvote
Create a resume that lands you SDE interviews at MAANG
Speaker
Anubhav Sinha
SDE-2 @
12 Jun, 2024 @ 01:30 PM

Introduction

Maven is a tool for project management and conceptual understanding that offers developers a complete build lifecycle framework. It provides ways for developers to handle builds, documentation, reporting, dependencies, release, and distribution.

In this blog, we will discuss Maven Architecture in deep detail. Let’s start going!

Maven Architecture

Importance of Maven

Maven primarily helps download dependencies, which are libraries or JAR files, for projects based on Java. As there may be various versions of distinct packages, the tool aids in obtaining the proper JAR files for each project.

Additionally, the tool helps develop the proper project structure in struts, servlets, etc., which is essential for execution.

Features of Maven

Maven features

Some essential features of Maven are as follows:-

1. It has robust reporting for errors and integrity.

2. It ensures uniform application across all projects.

3. The capacity to easily establish projects using guidelines.

4. It is also compatible with previous versions of its.

Maven Architecture

Maven architecture illustrates how to create and generate a report in accordance with the requirements and to carry out lifecycles, phases, goals, plugins, and other tasks starting at the very start. It includes plugin jar, plugin surefire, and plugin release. The diagram below shows the Maven architecture:-

Maven Architecture

In the above image, the first step entails setting up Maven, which is done by using a pom.xml file. All of the Maven's configurations are present in the POM file. 

In the second step, download the pom.xml dependencies from the central repository into the local repository.

There is no need to add each configuration to the pom.xml file from the remote repository because the tool offers a number of default settings once the user begins using Maven.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Repository in Maven

There are three types of maven repositories:-

Local Repository: The developer's computer serves as the project's local repository and is where all project files are stored. The dependency jars are all stored in this repository.

Central Repository: When dependencies are required but cannot be found in the local repository, the Maven community steps in to serve as the central repository. When necessary, Maven downloads the dependencies from this location.

Remote Repository: When Maven needs to download dependencies, it uses the repository located on a web server, which is referred to as the remote repository. When something from the remote repository is needed, it is first downloaded to the local repository and then used.

Maven Build Lifecycle

To deploy and distribute the target project, the Maven build follows a particular lifecycle.

There are three built-in lifecycles in Maven:-

default: It is the primary lifecycle that is responsible for project deployment. It consists of 21 phases from the validation process to the deployment stage.

clean: It is used to thoroughly tidy up the project and delete all files produced by the previous build. It consists of 3 phases.

site: It is used to produce the project's website documentation. It consists of 4 phases.

Maven Phases

A stage in the Maven build lifecycle is represented by a Maven phase. Each stage is in control of unique duty.

Maven phases

Some important phases in the Maven default build lifecycle are:-

1. validate: It verifies that all information required for the build is present.

2. compile: It compiles the source code.

3. test-compile: It compiles the test source code.

4. test: It executes unit tests.

5. package: It converts compiled source code into a format that can be distributed (jar, war,...).

6. install: Installation of the package into a local repository.

7. deploy: It copies the package to the remote repository.

Maven Goals

Each goal in Maven is responsible for a specific task. All of its associated goals are carried out sequentially when we run a phase. 

Some of the Maven phase and default goals are:-

1. compiler:compile: It binds the compile phase's compile goal to the compiler plugin.

2. The package phase is bound to the variables jar:jar and war:war.

3. Install: The installation is restricted to the installation phase.
 

Check out this problem - Smallest Distinct Window .

Frequently Asked Questions

How should one run the command to add JAR files to the local repository?

mvn install is used to add JAR files to the local repository. To manually add the JAR to the personal Maven repository, use the ensuing plugin: install-file-Dfile = <file path>.

What are Maven plugins used for? 

Maven plugins perform JAR file generation, WAR file generation, source code compilation, and unit testing.

In what locations are Maven dependencies kept?

Maven stores each JAR, dependency file, and other things it downloads in its local repository. All of the artifacts are stored locally in the Maven local repository, which is a folder on the local computer.

What is POM?

The project object model, or POM, is a crucial part of how Maven works. When performing a Maven objective or task, the pom file in the current directory is checked.

What does a Maven snapshot mean?

A snapshot is a specific version of a project that shows the current stage of development. For each build, Maven retrieves a snapshot of the project from the remote repository.

Conclusion 

Congratulations on finishing the blog! We have discussed the Maven Architecture. We further discussed the lifecycle, phase, and goal in Maven architecture.

We hope this blog has helped you enhance your knowledge of Maven Architecture. Do not stop learning! We recommend you read some of our maven articles: 

  1. Maven Interview Questions
  2. DropWizard - Setting up using Maven
  3. Addressing Modes of 8086
  4. Data Warehouse Architecture
     

Refer to our Guided Path to upskill yourself in DSACompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio!

But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. For placement preparations, you must look at the problemsinterview experiences, and interview bundles.

We wish you Good Luck! 

Happy Learning!

Previous article
What are the Features or Advantages of Maven
Next article
Maven Compiler Plugin Dependency
Live masterclass