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.
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:
- Maven Interview Questions
- DropWizard - Setting up using Maven
- Addressing Modes of 8086
-
Data Warehouse Architecture
Refer to our Guided Path to upskill yourself in DSA, Competitive Programming, JavaScript, System 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 problems, interview experiences, and interview bundles.
We wish you Good Luck!
Happy Learning!