BLOG

Img
Ranjan Singh Author's Perspective
img
5 Minutes read

Maven, The Build Automation Tool

The Maven project is developed by Apache Software Foundation, formerly a part of the Jakarta project. Maven is a powerful automation tool that is primarily used for Java-based projects. Maven helps tackle two critical aspects of building software –

  • It describes how the software is built
  • It describes the dependencies

Maven prefers convention over configuration. It dynamically downloads Java libraries and Maven plugins from one or more repositories such as the Maven Central Repository and stores them in a local cache. The artefacts of the local projects can also be updated with this local cache. Maven can also help build and manage projects written in C#, Ruby, Scala, and other languages.

Project Object Model (POM) file is an XML file that contains information related to the project and configuration information such as dependencies, source directory, plugin, goals, and much more used by Maven to build the project. This tool reads the pom.xml file to accomplish its configuration and operations.

Maven Objectives


Maven Architecture


Maven life cycle
There is a specific life cycle that Maven follows to deploy and distribute the target project.
There are three built-in life cycles:

  • Default– This is the main life cycle of Maven as it is responsible for project deployment
  • Clean– This life cycle is used to clean the project and remove all files generated by the previous build
  • Site– This life cycle aims to create the project’s site documentation

Each life cycle is made up of a sequence of phases. The default build life cycle consists of 23 phases as it is the main build life cycle of Maven. On the other hand, clean life cycle consists of three phases, while the site life cycle is made up of four phases.

Maven Phases

A Maven phase is nothing but a stage in the Maven build life cycle. Each phase executes a specific task.
Here are a few important phases in the default build life cycle –

  • Validate– This phase checks if all information necessary for the build is available
  • Compile– It compiles the source code
  • Test-compile– This phase compiles the test source code
  • Test– Unit tests are run in this phase
  • Package– This phase packages compiled source code into the distributable format (jar, war)
  • Integration-test– This phase processes and deploys the package if needed to run integration tests
  • Install– This phase installs the package to a local repository
  • Deploy– It copies the package to the remote repository

Maven executes phases in a specific order. This means that if we run a specific phase using the command such as MVN, this would specify the specific as well as all preceding phases as well.

Maven Goals

  • compiler:compile – compile phase
  • compiler:test – test-compile phase
  • surefire:test – test phase
  • install:install – install phase
  • jar and war:war – package phase

A Maven plugin is a group of goals. However, these goals aren’t necessarily bound to the same phase. For example, the Maven Failsafe plugin is responsible for running integration tests. For unit testing, we need Maven surefire plugin.

Install Maven

To install Maven, follow the below-mentioned steps to download and setup the same in your system:

  • Make sure that the system has Java installed (at least JDK 1.7) and JDK & JAVA_HOME environment variables configured
  • Go to the ‘Maven Apache Download’ page and download the binary zip file. Unzip it to the C drive, and the installation is complete
  • Configure the MAVEN_HOME path as environment variable and give path till the bin folder
  • Open the control panel and go to the system link
  • Click on the ‘Advanced System Settings’ tab at the left slide and navigate to the ‘Advanced’ tab
  • Click on the environment variables and add the MAVEN_HOME variable in system variables and give the path of the maven bin folder and save it.
    • To set the Environmental Variable – Go to Start menu > Edit Environment Variables > System Properties > Environment Variables > In the System Variables set the MAVEN_HOME path

Ebook
Top 10 Sitecore 9 Form Features to Increase Lead Conversions

Conclusion

Build tool is essential when it comes to building software, and it is even more critical if we aim at continuous integration and continuous delivery. Maven plays a crucial role in managing a project lifecycle, which typically includes validation, code generation, compilation, testing, packaging and much more. It is a software build tool that works in phases rather than tasks. It is basically used to manage the life cycle of a project. Maven makes the build management process much easier, as we will only need to specify the dependencies in the pom.xml files and Maven will take care of the rest!

Ranjan Singh Lead Testing at Altudo


Talk to our Experts

Talk to us about how we bring together 1:1 personalisation, deep Martech Expertise, CX & Demand Gen Strategy, Engagement Analytics & Cross-Channel Orchestration to drive award winning experiences that convert

Get in touch for a complimentary consultation or a demo today.

Expert Workshops

Free workshops, expert advice & demos- to help your realize value with Sitecore

Register

Session Presentations

  • Sitecore + SFMC= Marketing Success
  • Transforming The Future Of eCommerce
Meet Us

Giveaways:

Participate in our event survey , meet us at our booth , get free giveaways & a chance to win an iPhone 11

Let’s go
Close Button