What is Maven?

Lahiru Rajapakshe
5 min readMar 8, 2022

Maven is a popular open-source build tool developed by the Apache Group to build, publish, and deploy several projects. It is written in Java and is used to build projects written in C#, Scala, Ruby, etc.

Maven is a powerful project management tool that is based on POM (project object model). It is used for projects build, dependency and documentation.It simplifies the build process like ANT. But it is too much advanced than ANT.

Reasons for develop maven

  1. Adding set of Jars in each project:

In case of struts, spring, hibernate frameworks, we need to add set of jar files in each project. It must include all the dependencies of jars also.

2. Creating the right project structure:

We must create the right project structure in servlet, struts etc, otherwise it will not be executed.

3. Building and Deploying the project:

We must have to build and deploy the project so that it may work.

What does Maven help with?

  • Apache Maven helps manage all the processes, such as building, documentation, releasing, and distribution in project management.
  • The tool simplifies the process of project building. It increases the performance of the project and the building process.
  • The task of downloading JAR files and other dependencies is done automatically.
  • Maven provides easy access to all the required information.
  • Maven makes it easy for the developer to build a project in different environments, without worrying about the dependencies, processes, etc.
  • In Maven, it is simple to add new dependencies, all you need to do is to write the dependency code in the pom file.

What are the different elements that Maven takes care of?

In the process, it takes care of the following:

  • Builds
  • Dependencies
  • Reports
  • Distribution
  • Releases
  • Mailing list

What is Maven: Features

Maven is loaded with many valuable and useful features, which goes a long way towards explaining its popularity. Here are some of Maven’s more noteworthy features:

  • A huge, continuously growing repository of user libraries
  • The ability to set up projects easily, using best practices
  • Dependency management, featuring automatic updating
  • Backwards compatible with previous versions
  • Strong error and integrity reporting
  • Automatic parent versioning
  • Ensures consistent usage across all projects
  • It’s extensible, and you can easily write plug-ins using scripting languages or Java.

Advantages of Maven

  • Helps manage all the processes, such as building, documentation, releasing, and distribution in project management
  • Simplifies the process of project building
  • Increases the performance of the project and the building process
  • The task of downloading Jar files and other dependencies is done automatically
  • Provides easy access to all the required information
  • Makes it easy for the developer to build a project in different environments without worrying about the dependencies, processes, etc.
  • In Maven, it’s easy to add new dependencies by writing the dependency code in the pom file

Conversely, Maven has a few drawbacks.

  • Maven requires installation in the working system and the Maven plug-in for the IDE
  • If the Maven code for an existing dependency is unavailable, you cannot add that dependency using Maven itself
  • Some sources claim that Maven is slow

What is the difference between ANT and Maven?

ANT

  1. ANT has no formal conventions, so information is to be provided in the build.xml file.

2. ANT is procedural.

3. ANT has no life cycle.

4. ANT scripts are not reusable.

5. ANT is specifically a build tool.

Maven

  1. Maven has conventions, so information is not to be provided in the pom.xml file.
  2. Maven is declarative.
  3. Maven has a life cycle.
  4. Maven is mainly used as a project management tool.
  5. Maven plugins are reusable.

What is POM?

Project Object Model (POM) refers to the XML files with all the information regarding project and configuration details.

  • It has the description of the project, information regarding the versioning and configuration management of the project.
  • The XML file is in the project home directory. When we tend to execute a task, Maven searches for the POM in the current directory.

What all is included in the POM?

POM contains the following configurations:

  • Dependencies
  • Developers and contributors
  • Plugins
  • Plugin configuration
  • Resources

What are the minimum required elements for POM?

The minimum required elements for POM are:

  • project root
  • modelVersion — should be 4.0.0
  • groupId — project’s group id
  • artifactId — artifact (project) id
  • version — version of the artifact

What is meant by the term ‘Build Tool’?

A build tool is essential for the process of building. It is needed for the following procedures:

  • Generating source code.
  • Generating documentation from the source code.
  • Compiling of source code.
  • Packaging of the compiled codes into JAR files.
  • Installing the packaged code in a local repository, server, or central repository.

What is a Maven Repository?

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 allows Maven to download dependencies.

There are three types of repositories:

  • Local Repository
  • Remote Repository
  • Central Repository

What are the different types of Maven Repositories?

1. Local Repository:

  • Local repository refers to the machine of the developer where all the project material is saved.
  • The local repository contains all the dependency jars.

2. Remote Repository:

  • The remote repository refers to the repository present on a server that is used when Maven needs to download dependencies.
  • Whenever anything is required from the remote repository, it is first downloaded to the local repository, and then it is used.

3. Central Repository:

  • 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 in the local repository whenever needed.

What is Clean, Default, and Site in Maven?

There are three built-in build life cycles:

  • Clean: The clean lifecycle looks after project cleaning.
  • Default: The default lifecycle handles the project deployment.
  • Site: The site lifecycle refers to the creation of the project’s site documentation

How does Maven Architecture work?

  • The first step is to read the pom.xml file.
  • Then, it downloads the dependencies defined in pom.xml into the local repository from the central repository.
  • Lastly, it creates and generates a report according to the requirements, and executes life-cycles, phases, goals, plugins, etc.

What is Maven Build Lifecycle?

Maven lifecycle is a collection of steps that are to be followed, to build a project. There are three built-in build lifecycles:

  • Default: Handles project deployment.
  • Clean: Handles project cleaning.
  • Site: Handles the creation of the project site’s documentation.

What are the different phases in the Maven Build Lifecycle?

Thank you !

--

--