Learn about Apache Maven- A Build Automation Tool

What’s up, everyone! Today we will be going to talk about Maven.

We will start with the quick intro and then list down the advantages of using it. After all this, we will see its installation process and then a few technical terms which are essential for a beginner. So, let’s get started!

What is Maven?

Apache Maven is a project management software, and we can say it is a comprehension tool. It is based on the concept of the project object model (POM) [will be discussed later in the articles], Maven can manage a project’s build, reporting, and documentation from a central piece of information.

Apache Maven is a build tool, and it does the task just like Ant, which is again an extraordinary build Tool. This is a software project management tool that gives a new concept of the project object model (POM). Maven allows the developer to automate the handling of the creation of the original folder format, performing the assortment and testing and the packaging and deployment of the final output. It cuts down the considerable number of steps in the base process, and it makes it jus one-step process to do a build.

Why is Maven Used?

To sum up, Maven simplifies and standardizes the project build process. It handles team collaboration, compilation, distribution, documentation, and separate tasks seamlessly. Maven increases reusability, and it also takes care of most of the build-related tasks. It works in helps many steps such as adding jars to the project library, building reports, and executing Junits test cases, creating Jar, War, Ear files for the project, and even many more things.

A highly significant aspect of Maven is the purpose of repositories to manage jar files.

The Maven can further be used in building & managing the projects written using languages like C#, ruby, and other programming languages.

Let’s take a look at the following Maven advantages.

Convention over configuration

  • Its configuration is very minimal.
  • It has managing dependencies.

Multiple/Repeated builds can be achieved

  • Automation makes it easy.

Plugin management, testing, and development

  • It has the ability to run JUnit and other integration tests.
  • It makes the development process clear.

Provisions to check the status of every build

  • It avoids inconsistent setups.
  • Standard and uniformed infrastructure among projects.

Setting up Maven Environment

The installation of Maven includes the following steps:

  • Check whether the system has Java installed or not. if not then install java
  • Check whether java Environment variable is set or not. If not, then set java environmental variable.
  • Download Maven
  • Unzip the maven download at one place in the system.
  • Now, add the bin directory of the created directory apache-maven-3.6.2 to the PATH environment variable and system variable.
  • Open cmd and run mvn -v command to confirm the installation.

That’s all

To get the detailed steps of the installation, follow the below YouTube guide to setup Maven Environment as we don’t want to make this article simple reading stuff and boring too.

As this is a beginner guide so it must include technical terms related to MAVEN. So here are few, which are very important:

Maven Local Repository

Maven Local Repository is the set where Maven stores all the project jars files or libraries or dependencies. By default, the folder name set to ‘.m2 ‘, and by default, the location is ‘Libraries\Documents\.m2 ‘.

Maven Central Repository

Maven central repository is the default location for Maven to download all the project dependency libraries for the use. For any library involved in the project, Maven first looks into the .m2 folder of Local Repository, and if it does not find the needed library, then it seeks in Central Repository and loads the library into the local repository.

Maven POM

POM is a Project Object Model XML file that has information about the project and configuration details needed by Maven to develop the project. It contains default values for most projects. Some of the structures that can be defined in the POM are the project dependencies, plugins that can be executed, and of course, the build profiles.

Elements used in Creating pom.xml file

  • project- Project is the root element of the pom.xml file.
  • modelVersion- It means the version of the POM model you are working with.
  • groupId- It implies the id for the project group. It is unique, and Most often, you will apply a group ID that is related to the root Java package name.
  • artifactId- This is used to provide the name of the project you are building.
  • Version- This element consists of the version number of the project. If your project has been released in various versions, then it is convenient to present the version of your project.

Dependency Keyword

Dependencies are the libraries, which are needed by the project. Like Log4j jars, Apache Poi jars, Selenium Jars are few libraries that are required for the project. Dependencies, in the Maven pom.xml, are mentioned like this:

<dependencies>

      <dependency>
         <groupId>com.companyname.groupname</groupId>
         <artifactId>App-Core-lib</artifactId>
         <version>1.0</version>
      </dependency>

</dependencies>

Surefire Plugin

The Surefire Plugin is needed during the test phase of the build lifecycle to implement the unit tests of an application. It makes reports in 2 different file formats like plain text file, XML files, and in HTML files also. Even if you are using Junits framework or TestNG for reporting, this plugin is a must for use, as it helps Maven to find tests.

Practical Application Of Maven

When working on a specific java project, and that project has a lot of dependencies, builds, requirement, then working with all those things manually is hugely complex and laborious. Thus using some tools that can work out these works is truly helpful.

And Maven is such a build management tool which can perform all the things like adding dependencies, using the classpath to project, making war and jar file automatically and many new things.

Conclusion

This tool is beneficial when it comes to building projects. I wish you success in your JAVA project. If you are looking for a video tutorial, then you may check out the Maven crash course.