Maven Beginners Tutorial

Maven Tutorial

Introduction to Maven

Maven is a build automation tool used primarily for Java projects. Maven addresses two important aspects of building software:
First: It describes how software is built
Second: It describes its dependencies.

Unlike earlier tools like Apache Ant, it uses conventions for the build procedure and only exceptions need to be written down.

An XML file describes the software project being built, its dependencies on other external modules and components, the build order, directories, and required plug-ins.

It comes with pre-defined targets for performing certain well-defined tasks such as compilation of code and its packaging.

What Is a Build Tool?

Build tools are programs that automate the creation of executable applications from source code. The building incorporates compiling, linking and packaging the code into a usable or executable form.

In small projects, developers will often manually invoke the build process. This is not practical for larger projects.

Where it is very hard to keep track of what needs to be built, in what sequence and what dependencies there are in the building process. Using an automation tool like Maven, Gradle or ANT allows the build process to be more consistent.

Few of the important features of Maven are:

Ø  Simple project setup that follows best practices - get a new project or module started in seconds.

Ø  Consistent usage across all projects - means no ramp-up time for new developers coming onto a project.

Ø  Superior dependency management including automatic updating, dependency closures (also known as transitive dependencies)

Ø  Able to easily work with multiple projects at the same time

Ø  Extensible, with the ability to easily write plugins in Java or scripting languages

Ø  Instant access to new features with little or no extra configuration

Build Life cycles In Maven

Build lifecycle is a list of named phases that can be used to give order to goal execution.
One of Maven's standard life cycles is the default lifecycle, which includes the following phases, in this order

1 validate
2 generate-sources
3 process-sources
4 generate-resources
5 process-resources
6 compile
7 process-test-sources
8 process-test-resources
9 test-compile
10 test
11 package
12 install
13 deploy

Plugins In Maven

Most of Maven's functionality is in plugins. A plugin provides a set of goals that can be executed using the following syntax:

mvn [plugin-name]:[goal-name]

For example, a Java project can be compiled with the compiler plugins compile-goal by running mvn compiler: compile . There are Maven plugins for building, testing, source control management, running a web server, generating Eclipse project files, and much more. Plugins are introduced and configured in a <plugins>-section of a pom.xml file.
Some basic plugins are included in every project by default, and they have sensible default settings.

POM In Maven

A Project Object Model (POM) provides all the configuration for a single project. General configuration covers the project's name, its owner and its dependencies on other projects.

One can also configure individual phases of the build process, which are implemented as plugins.

For example, one can configure the compiler-plugin to use Java version 1.5 for compilation, or specify packaging the project even if some unit tests fail.

Larger projects should be divided into several modules, or sub-projects, each with its own POM. One can then write a root POM through which one can compile all the modules with a single command. POMs can also inherit configuration from other POMs.

All POMs inherit from the Super POM by default. The Super POM provides default configuration, such as default source directories, default plugins, and so on.

Maven Archetype

An archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made.

Maven Artifact

In Maven artifact is simply a file or JAR that is deployed to a Maven repository. An artifact has
-Group ID
-Artifact ID
-Version string.
The three together uniquely identify the artifact. All the project dependencies are specified as artifacts.



My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post