In this article, I am going to explain "What is Maven?" and "What is the use of Maven". One reason for writing this blog is when I was interviewed for my role at Mulesoft a few months ago, I was asked "What is Maven?". After my interview, I searched for answers but didn't find them gathered in one place. Before getting started there are some terms that we need to understand.
What is Maven?
Maven is a powerful project management tool that is based on POM(project object model). It is used for project build, dependency, and documentation.
What is pom.xml?
POM is an acronym for Project Object Model. It contains information about the project and the configuration of the project such as dependencies, build directory, source directory, test source directory, plugins, goal, etc. Maven reads pom.xml and then executes the goal.
What is settings.xml?
The settings element in the settings.xml file contains elements used to define values that configure Maven execution in various ways, like the pom.xml, but should not be bundled to any specific project, or distributed to an audience. These include values such as the local repository location, alternate remote repository servers, and authentication information.
Please refer for more info: https://maven.apache.org/settings.html
Mechanism of Maven with Anypoint Studio:
Summary:
Anypoint Studio comes with the embedded Maven. Maven reads the pom.xml file and downloads the jar files defined in the pom.xml file. Now, the question arises from where Maven downloads these jar files. Maven downloads these jar files from the central repository and stores them in the local repository of your project. Details of these repositories are defined in settings.xml as mentioned above.
Brief:
How Maven Downloads Dependencies: there are three different Repos as below
Repositories:- Maven uses repositories to store and retrieve artifacts (JARs, WARs, and other binary formats). There are three main types of repositories: Central, Remote, and Local.
Central Repository:- Managed by the Maven community, it contains a large number of commonly used libraries.
Remote Repository:- Custom repositories set up by organizations or third parties to host proprietary or uncommon libraries.
Local Repository:- Located on the developer's machine, it caches downloaded artifacts so Maven doesn't need to repeatedly download them.
Process:
When you build a Maven project, Maven looks at the dependencies specified in your pom.xml. Maven first checks your local repository to see if the dependency artifacts are present. If not found locally, Maven then checks the central repository. If the artifact isn't in the central repository (or if Maven is configured to look at other repositories), it will check any remote repositories defined in the pom.xml or in Maven's settings. Once Maven locates the needed artifact, it downloads it and stores it in the local repository for future use.
This is the end of the explanation. I would like to mention the names who helped me understand the concept and provided me with the source. Thanks to anuragsh27 and alheredi. You can find them at https://help.mulesoft.com