Lesson 1 of 5By Ishan Gaba
Last updated on Apr 2, 20213215Every application that we use today requires a set of configurations that need to be completed. These configurations were once completed manually, but after the advent of Maven and other automation tools, this tedious task became automated. Maven is a DevOps tool that automates the entire process of building and developing these applications. This introduction to maven tutorial will help you learn everything that you need to excel in Maven.
The topics we will be covering in this introduction to maven tutorial include:
Let’s begin the introduction to maven tutorial with understanding why we need Maven in the first place.
Maven is a software project management build tool based on Project Object Model (POM). The tool is typically used for Java-based projects. Every Java project requires certain dependencies, which are automatically downloaded when running a Maven build. This simplifies everyday tasks for Java developers and helps them with their projects.
Maven helps retrieve the correct JAR files for each project, as there may be different versions of separate packages. If you want to download dependencies, you no longer need to visit each software's official website. It can be quickly done now by visiting "mvnrepository.com."
Next up in the introduction to maven tutorial we will learn what exactly maven is. Maven is a popular open-source build tool that the Apache Group developed for building, publishing, and deploying several projects. Maven is written in Java and is used to create projects written in C#, Scala, Ruby, and so on. The tool is used to build and manage any Java-based project. It simplifies the day-to-day work of Java developers and helps them with various tasks.
Maven is based on Project Object Model (POM) and focuses on simplification and standardization of the building process.
During the process, Maven takes care of the following elements:
In the next section of the introduction to maven tutorial, we will learn what a build tool is.
A build tool is essential for the process of building, as these are the tools that automate the process of creating applications from the source code. The build tool compiles and packages the code into an executable form.
A build tool does the following tasks:
In this section of the introduction to maven tutorial, we will learn about maven repositories, and their types.. Maven repositories refer to the directories of packaged JAR files that contain metadata. The metadata refers to the POM files relevant to each project. This metadata is what enables Maven to download dependencies.
There are three types of repositories:
Local repository refers to the developer’s machine, which is where all the project material is saved. This repository contains all the dependency jars.
The remote repository refers to the repository present on a web server, which is used when Maven needs to download dependencies. This repository works the same as the central repository. Whenever anything is required from the remote repository, it is first downloaded to the local repository, and then used.
Central repository refers to the Maven community that comes into action when there is a need for dependencies, and those dependencies cannot be found in the local repository. Maven downloads the dependencies from here whenever needed.
The next important aspect of the introduction to maven tutorial is to understand why Maven uses convention and not configuration.
Convention is used when the developers are not required to create the build processes. The users do not have to specify the configurations in detail, and once the project is created, it will automatically create a structure. With configuration, on the other hand, developers are supposed to create the build processes manually.
Maven uses convention over configuration so developers just have to create a Maven project. The rest of the structure is automatically generated. There are many conventions present in Maven for setting up a plan, building the artifacts, releasing the code, and running unit tests. The developer simply places the files, and there is no need to define any configuration in pom.xml.
The feature helps developers to freely build any Maven project without worrying about the need to know about the workings of each plugin. The Maven plugins look over the project management and build-related works.
In this section of the introduction to maven tutorial we will learn about the five primary and most significant concepts of Maven:
Next up in the introduction to maven tutorial, we will dig deeper into the features of maven. Apache Maven manages all the processes, like building, documentation, releasing, and distribution in project management.
The projects created in Maven contain POM files that describe the aspect of the project essentials. Maven architecture shows the process of creating and generating a report according to the requirements and executing lifecycles, phases, goals, plugins, and so on—from the first step.
The Maven build life cycle is a sequence of steps that need to be followed in order to build a project, which eventually helps to execute goals.
The following are the phases of the build life cycle:
There are three types of standard life cycles:
The default or build life cycle is the primary cycle that is responsible for building the application. There are 21 different phases in this primary life cycle, starting from the process of validation to the step of deployment.
The clean life cycle handles project cleaning. The clean phase consists of the following three steps:
The mvn post-clean command is used to invoke the clean lifestyle phases in Maven.
The Maven site plugin handles the project site's documentation, which is used to create reports, deploy sites, etc.
The phase has four different stages:
Ultimately, the site that is created contains the project report.
The first step in creating a project is to go inside the terminal, and enter the following command:
mvn -version |
The version of Maven is displayed on the screen.
Now, let’s run the following commands:
mvn archetype : generate mkdir temp cd temp |
Maven downloads some of the plugins in order to handle specific executions.
Maven will then have the user choose a number or version.
The sample project will be created with the artifactId you have provided.
GO inside that directory and verify what files are created:
cd sampleproject ls -alrt cat pom.xml vi pom.xml |
When the pom.xml file is opened, you can see the attributes on the screen. It shows the groupId, artifactId, the JAR file, and the version. You can also add your own custom dependencies.
If you run the clean command, it will be classified as a Maven project.
mvn clean install |
A pom.xml file is already present in the local repository. The execution of the steps will take place accordingly.
Eventually, you can see a couple of JAR files being created in the directory.
You can create a new project with this method, and based on our understanding, amendments can be made in the dependencies. Hence, a required final result can be obtained.
Interested to begin a career in DevOps? Enroll now for the DevOps Certification Course. Click to check out the course curriculum.
In our introduction to maven tutorial, we have explored why Maven is used, and all the introduction to maven,the fundamental concepts of Maven, and maven architecture, and its lifecycle.. Some of the many areas we covered include build tools, convention over configuration, and POM. Finally, we reviewed the process of creating our first project in Maven, with the help of a hands-on demo.
Do you have any questions for us? Leave them in the comments section below, and we will have our experts answer them for you.
DevOps is the way of the future, and companies are actively seeking highly-skilled professionals in this exciting field. To boost your career, check out our DevOps Engineer Master’s program through which you don’t only learn introduction to maven but also learn how to leverage powerful tools like Maven, Git, Docker, Jenkins, and more. What are you waiting for?
Ishan Gaba is a Research Analyst at Simplilearn. He is proficient in Java Programming, Data Structures, and Project Management. Graduated in Information Technology, Ishan is also passionate about writing and traveling.
How to Create a Maven Project in Eclipse
Getting Started With Multi-Cloud Architecture
Project Life Cycle Vs Product Life Cycle
How to Install Maven™ on Windows and Ubuntu
What is Maven: Here's What You Need to Know
Introduction to Artificial Intelligence: A Beginner's Guide