Introduction to Maven Build Tool
305.1 - Introduction to Maven Build Tool
Learning Objectives:
In this presentation, we will discover how to use and install Maven and how to use Maven in Java. By the end of this presentation, learners will be able to:
Demonstrate the setup of Maven on local machine.
Describe the Core Concepts of Maven.
Explore Maven’s ability to describe, build, and manage Java software projects using the Project Object Model (POM) in XML.
Table of Contents
Introduction to Maven.
Advantages of Using Maven.
Core Concepts of Maven.
Installation of Maven.
Overview of Project Object Model.
Sample for Pom.xml File.
Maven Build Lifecycle.
Overview of Dependencies and Repositories.
Search for Dependencies.
Maven Plugins.
How Maven Works.
Introduction to Maven
Maven is a Java-based tool. The Apache Group developed Maven to support the development and building of multiple projects together for publishing and deploying multiple projects and generating the reports.
Maven aims to describe two important things:
How a software is built.
The dependencies (jar files), plug-ins, and profiles that the project is associated with in a standalone or distributed environment.
A more formal definition of Apache Maven is "a project management tool, which encompasses a project object model, a set of standards, a project lifecycle, a dependency management system, and the logic for executing plugin goals at defined phases in a lifecycle.”
Advantages of Using Maven
Dependencies.
Convention over configuration.
Multiple/repeated builds.
Automation.
Plugin management.
Testing.
Development process.
Build status.
Consistent setups.
Standard and uniformed directory structure.
Core Concepts of Maven
Project Object Model (POM) Files: When you execute a Maven command, you give Maven a POM file to execute the commands on.
Dependencies and Repositories: Dependencies are external JAR files (Java libraries) that your project uses.
Build LifeCycles, Phases, and Goals: A build lifecycle consists of a sequence of build phases, and each build phase consists of a sequence of goals.
Profiles: Build profiles are used if you need to build your project in different ways.
Plugins: Build plugins are used to insert extra goals into a build phase.
Installation of Maven
Verify that your system has JDK installed. If it does not, install Java.
Check that the Java Environment variable is set. If it is not, set the Java Environment variable using this link: install java and setting environment variable.
Download Maven.
Unpack your Maven zip at any place in your system (folder).
Adding Maven to the Environment variable (system variable environment and PATH environment variable).
Guided Lab - Installation of Maven
Find the GLAB - 305.1.1 - Installing Maven on Windows on Canvas under the Assignments section.
Overview of Project Object Model
Project Object Model (POM) in Maven is a core element.
The pom.xml contains the information related to the project, which is built in.
It contains all of the necessary information about the configuration details and the dependencies and plugins included in the project.
Maven provides six scopes: compile, provide, runtime, test, system, and import.
Sample for Pom.xml File
A pom.xml will always start with the root element called <project> under which all of the other required configurations (see below) will be made.
Maven Build Lifecycle
The sequence of steps defined in order to execute the tasks and goals of any Maven project is known as build lifecycle in Maven.
Developers only need to learn a small set of commands to build any Maven project, and the POM will ensure that they get the results desired.
Maven comes with three built-in build lifecycles.
Overview of Dependencies and Repositories
Dependencies are external Java libraries required for the project, and repositories are directories of packaged JAR files.
The local repository is just a directory on your machine’s hard drive.
To download the required artifacts of the build and dependencies (JAR files) and other plugins, which are configured as part of any project, there should be a common place where all such artifacts are placed. This commonly shared area is called a Repository.
Search for Dependencies
When Maven starts executing the building commands, it starts searching the dependencies.
It scans through the local repositories for all of the configured dependencies. If found, it continues with further execution. If the configured dependencies are not found in the local repository, then it scans through the central repository.
If the specified dependencies are found in the central repository, those dependencies are downloaded to the local repository for future reference and usage. If not found, Maven starts scanning into the remote repositories.
Maven Plugins
Maven is actually a plugin execution framework, where every task is performed by plugins.
A plugin generally provides a set of goals, which can be executed using the following syntax: mvn [plugin-name]:[goal-name].
How Maven Works
Check Your Knowledge
What is Maven?
What is POM?
What is Clean, Default, and Site in Maven?
What is a Maven Repository?
What are the different types of Maven Repositories?
What is a Maven Artifact?
Summary
In this lesson, we explored the Maven Build Tool. Maven simplifies and standardizes the project build process.
It handles compilation, distribution, documentation, team collaboration, and other tasks seamlessly.
Maven increases reusability and takes care of most of build-related tasks.
To configure the Maven, you need to use Project Object Model, which is stored in a pom.xml-file.
In the context of Maven, a dependency is simply a JAR file used by a Java application.
There are exactly two types of repositories: local and remote.
References
Apache Maven Project - Introduction.
Introducing Maven.
Questions?
Last updated