What is Maven?
Maven (mvn) is a popular open-source build tool developed by the Apache Group that allows you to build, publish, and deploy many projects at the same time. It was first released on July 13, 2004.
It is developed in Java and can be used to build projects in Java, C#, Scala, Ruby, and other languages.
Maven is based on the POM (Project Object Model) and aims to simplify and standardize the build process.
In the process, it takes care of the following:
- Build
- Dependencies
- Reports
- Distribution
- Releases
- Mailing List
Maven is chiefly used for Java-based projects. This tool helps in building the code downloading DEPENDENCIES.
What is a Dependency?
A dependency is just an additional archive (.jar or.zip) that the present project requires in order to compile, build, test, and/or deploy.
These project dependencies are described collectively in the POM.xml file located in the root directory.
This tag has the following dependencies:
<dependencies> ... <dependencies/>
Maven assists in obtaining the correct JAR/WAR files from projects. It is no longer necessary to visit the official website of any product to get dependencies after the arrival of Maven. It is now simple to do so by visiting https://www.mvnrepository.com
Maven Directory Structure:
Maven Functionality:
Firstly, the developers will write their code and add all the required dependencies to run the application. Developers mention their application and project information inside the POM.xml file and run these commands:
- mvn clean
To clean up the mvn project by deleting the target directory. The Target directory is used to house all outputs of the build.
- mvn compiler:compile
To compile the Java source code
- mvn compiler:testCompile
To compile the test case classes.
- mvn install / mvn package
This both commands will build the mvn project by installing appropriate dependencies.
According to the commands from the life cycle phases, downloads dependencies defined in POM.xml into the local repository from the central repository.
What is the Local and Central Repository?
In Maven terminology, a repository is a directory where all the project jars, library jar, plugins, or any other project-specific artifacts are stored and can be used by Maven easily.
There are three types of Maven repositories. The image below will give you an understanding of these three types.
1. local
2. central
3. remote
The Maven local repository is a folder on your PC. When you run any maven command for the first time, it creates it.
Maven local repository stores all of your project's dependencies (library jars, plugin jars etc.). Maven automatically uploads all dependency jars into the local repository when you execute a Maven build. It aids in avoiding references to dependencies kept on a remote workstation each time a project is built.
Central Repository:
Maven central repository is a repository made available by the Maven community. It includes a huge number of widely used libraries.
When Maven cannot identify a dependency in the local repository, it searches the central repository at https://repo1.maven.org/maven2/
Remote Repository:
Maven does not always detect the indicated dependency in the central repository. It then terminates the build process and prints an error message to the console. To avoid this, Maven supports the idea of a Remote Repository, which is the developer's own custom repository containing needed libraries or additional project jars.
0 Comments
Post a Comment