Welcome to linuxnix.com. We have already covered the basics about Maven. In this blog, we are going to know more about it. We will focus on the types of Maven repositories, deep into POM, how Maven works, etc. If you want to understand the basics of Maven, click here.
Maven Overview
Super POM
The Super POM is the Maven’s default POM which is also called as Parent POM or Base POM. This is usually placed on the root directory of the project and there can be multiple subprojects which can have multiple POMs. These POMs from the subprojects are called Child POMs.
An easy way to look at the default configurations of the super POM is by running the following command.
mvn help:effective-pom
The minimum requirement for POM
There are few minimal requirements for POM without which Maven cannot parse POM while building.
- Project root
- Model Version
- GroupId
- ArtifactId
- Version
Maven uses the configuration from Super POM plus project configuration to execute the task. It runs sensible default behavior for projects, when the project is created it creates default structure. Developers are required only to place files in the respective location and no need to define any configuration in POM.xml. Below shows the default path:
- Source code: <project-location>/src/main/java
- Resources: <project-location>/src/main/resources
- Tests: <project-location>/src/test
- Complied byte code: <project-location>/target
- Distribution JAR: <project-location>/target/classes.
Maven Directory Structure
The directory structure of an ideal Maven project has the following directory entries:
Directory name | Purpose |
project home | Contains the pom.xml and all subdirectories. |
src/main/java | Contains the deliverable Java source code for the project. |
src/main/resources | Contains the deliverable resources for the project, such as property files. |
src/test/java | Contains the testing Java source code (JUnit or TestNG test cases, for example) for the project. |
src/test/resources | Contains resources necessary for testing. |
Maven Settings File
Maven has two settings file. In these files, you can configure settings for Maven across all Maven POM files. For instance, you can configure the location of the local repository, the active build profile, etc. The setting files are settings.xml and are located in these two locations:
- The Maven installation directory: $M2_HOME/conf/settings.xml
- The user’s home directory: ${user.home}/.m2/settings.xml
The files are optional. If both files are present, the values in the user’s home setting file override the value in Maven installation settings file.
Maven Repositories
For Maven to download required artifacts of the build, dependencies and other plugins which are configured as the part of the project, there should be a commonplace. This common shared area is called Maven Repository. Maven has mainly three types of repositories.
- Local repository
- Central repository
- Remote repository
Maven searches all these three repositories for dependencies in the above sequence. First in the local repository, then in the central repository and finally in the remote repository, if specified in the POM.
Maven Local Repository
The Local repository is the directory on the developer’s computer. This directory contains all the dependencies Maven downloads. The same maven repository is used for several different projects. The Maven just need to download the dependency once.
By default, maven keeps the local repository under user-home/.m2 directory. The path can be changed by changing the configuration of the settings file. Below is an example.
<settings> <localRepository> D:\data\java\products\maven\repository </localRepository> </settings>
Maven Remote Repository
This repository is situated on the web server from which Maven can download dependencies. It can be located anywhere on the internet or inside a local network. This repository is often used to host projects internal to your organization, which are shared by multiple projects.
Even common security policies can be implemented across the organization which can be shared by multiple projects. It can be hosted in a private network where the developers form an organization will only have the access to use it.
Maven Central Repository
The Maven Central repository is the repositories provided by the Maven community. By default, Maven searches the dependencies in the local repository. When not found, it searches it in the Central repository.
You don’t need any special configuration to access Central repository. Many developers use the predefined dependency from here and even contribute back to the community.
Conclusion
So, In this blog, we went deeper into Maven and understood various part of Maven and their functionalities. In our next blog, we will go deep into some practical sets where we will undergo the installation, the life cycle of maven build and all the Maven commands. If you wish to go through the Maven basics, click here.
Stay tuned with linuxnix.com.
Latest posts by Ankesh K (see all)
- Deep-Dive into Jenkins – What are all Jenkins functionalities ? - January 10, 2019
- What are different Maven Plugins and how to build a Maven project? - January 7, 2019
- What is a Maven POM File and what are different Maven Repositories? - January 3, 2019
- What is Maven and what are its benefits? - December 31, 2018
- What are the different ways to install Jenkins ? - December 27, 2018