Welcome to linuxnix.com. We are here to learn about a build tool called Maven. In this blog, we will go through Maven basics, its characteristics, advantages, disadvantages, Maven POM and its comparison to other tools.

 

What is Maven?

Maven is a project management and comprehension tool written in Java language that provides developers a complete build lifecycle. It is mainly used for Java projects based on the Project object model (POM). It builds, reports and document from the information present in POM.

It helps developers to automate the builds, creating reports and test automation steps. Maven provides developers to manage the following:

  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Releases
  • Distribution
  • Mailing list

 

Maven Evolution

Maven was originally designed to build projects for Jakarta Turbine project. There were several projects and each project was built with a slightly different build file. Apache group then built Maven which can build multiple projects together and publish the jar/war files locally or across different tools.

 

Maven System Requirement

Maven is a Java-based tool so the basic requirement is Java.

JDK 1.7 or above
Memory No min. requirement
Disk Space No min. requirement
Operating System Almost all the Operating Systems

 

Features of Maven

  • Immediate access to new features in a small amount of time or no time.
  • It is able to build any number of projects which has predefined outputs such as war, jar.
  • Integration with VCS is not a tough task.
  • It allows users to reuse JARs from projects.
  • It is easy to migrate for new features of Maven.
  • Using the metadata, it can generate pdf or websites.
  • One big advantage is parallel builds.
  • Easy to write plugins in JAVA or any scripting languages.
  • It has very good error reporting mechanism.
  • The Maven wiki is the place where you can get the solution for all your issues.

 

What is Project Object Module (POM)?

POM stands for Project Object Module. It is a fundamental unit in Maven which is written in XML and symbolizes as “pom.xml”. POM contains the information about the project and various configuration oh how the project has to be built by Maven.

POM also contains the goals, dependencies, and plugins. While executing a maven build, Maven searches for a POM in the parent directory of the project which can be linked to different other POMs for different applications associated with it. These are called Parent and Child POMs (We will discuss this in our future blogs).

Configuration details included in POM are mentioned below:

  • Project dependencies
  • Build profiles
  • Project version
  • Mailing list
  • Goals
  • Plugins
  • Developers

Note: There should only be a single POM file for each project. Below is an example of the POM files.

<project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0"
 http://maven.apache.org/xsd/maven-4.0.0.xsd>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>my-project</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>
</project>

(Refer for a complete POM example – https://github.com/iankesh/game-of-life/blob/master/pom.xml)

 

Maven benefit to Developers

Maven helps developers to create Java-based projects more easily. They can add features to their projects in a more flexible way and even downloads the project dependency automatically. Below are some of the popular IDEs supporting development with Maven.

  1. Eclipse
  2. IntelliJ IDEA
  3. JBuilder
  4. NetBeans
  5. MyEclipse

 

Advantages of Maven

  • Multiple builds at the same time.
  • Once your project is able to build, it can be re-build on a different machine i.e. repeatable on the build servers.
  • The build system is standardized. If anybody knows about maven, they can easily build.
  • There are thousands of plugins to carry out various goals. These are configured just by adding a reference to POM.
  • Minimal setup or configuration is required to build artifacts.

 

Disadvantages of Maven

  • Maven is variable.
  • It is relaxed.
  • Repositories of Library are not always safe.
  • Learning Maven is lengthy as compared to ANT.

 

Differences between Maven, Gradle, and Ant

Ant Maven Gradle
Released in 2000 Released in 2004 Released in 2012
Build Script is in XML format i.e Build.xml Build script is in XML format i.e; POM.xml Build script is in DSL format i.e; Build.gradle
Compile the code by running ant compile Compile the code by running maven compile Compile the code by running gradle classes.
Run tasks to create jar: ant jar Run tasks to create jar: mvn package Run tasks to create jar: grade tasks –all

 

Conclusion

Maven is an automation building tool. In this blog, we went through the Maven basics and understood its features. For beginners, Maven is a very good build tool which is easy to understand and contains Central repo called Maven repository, you just need to mention dependencies and it will pull them from the central repo. In the next blog, we will go deep into Maven functionalities, commands, goals and even build a maven project.

Stay tuned with linuxnix.com.

 

The following two tabs change content below.
Hello, my name is Ankesh and I work as a Sr. DevOps Engineer in an IT firm where I have hands-on experience in supporting and automating deployments in the cloud, leveraging configuration management and DevOps process. I like to keep myself always in the learning path and love to share knowledge with others. One of my other interests is Graphics Designing and my hobbies are Cooking and Playing Cricket.