BreadcrumbHomeResourcesBlog What Is Maven? July 15, 2020 What Is Maven?Java ToolsJava Application DevelopmentBy Pavel FolIn this blog, we give an overview of Maven (MVN), how it's used, how it works, and compare the benefits and popularity of Maven, Gradle, and Ant.Table of ContentsWhat Is Maven (MVN)?What Is Maven Used For?How Does Maven Work?Maven Plugins and Build LifecycleIs Maven Popular?Maven vs. GradleMaven vs. AntFinal ThoughtsTable of Contents1 - What Is Maven (MVN)?2 - What Is Maven Used For?3 - How Does Maven Work?4 - Maven Plugins and Build Lifecycle5 - Is Maven Popular?6 - Maven vs. Gradle7 - Maven vs. Ant8 - Final ThoughtsBack to topWhat Is Maven (MVN)?Maven, or MVN, is a powerful software project management tool used in the Java development environment to manage and build projects as well as to maintain dependencies.Back to topWhat Is Maven Used For?Without a build tool, managing and building Java applications would be a very painful, long, and often-repeated process. With Maven, it’s easy to maintain the project libraries using the dependency system and build the project using one of the goals.Back to topHow Does Maven Work?Maven itself requires Java installed on your machine. You can verify if Maven is installed on your machine by running “mvn -v” in your command line/terminal. Maven is based on the Project Object Model (POM) configuration, which is stored in the XML file called the same – pom.xml. It is a structured format that describes the project, it’s dependencies, plugins, and goals.<?xml version="1.0" encoding="UTF-8"?> <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.example</groupId> <artifactId>SampleProject</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13</version> <scope>test</scope> </dependency> </dependencies> </project> The above example represents the structure of a simple project that has one dependency on a 3rd party library, JUnit. This file is always in the root of the project folder and when the Maven control commands are executed, the file from the current location is used. Maven also supports multi-module projects, where each of the modules is represented by individual pom.xml stored in respective directory.Back to topMaven Plugins and Build LifecycleAll the plugins are called using the following command syntax “mvn [plugin_name]:[goal]”. The goal basically represents the function of the plugin user wants to execute. There are already a few plugins present in Maven, so you can often see being it used without the [plugin_name], such as “mvn compile”. As there are sometimes more plugins called during the application build, Maven defines Build Lifecycle. This is used to associate plugin with one of the phases and when the phase is executed, so it’s the plugin. Maven defines the default lifecycle by the following phases:validate - validate the project is correct and all necessary information is availablecompile - compile the source code of the projecttest - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployedpackage - take the compiled code and package it in its distributable format, such as a JAR.verify - run any checks on results of integration tests to ensure quality criteria are metinstall - install the package into the local repository, for use as a dependency in other projects locallydeploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.Just getting started with Maven? Our one-page cheat sheet includes the above info, and a lengthy list of Maven options to help you on your way.Get Cheat SheetBack to topIs Maven Popular?Maven is without any doubt one of the most popular build tools in Java. Together with Gradle, a different build tool with similar functionality, they are used in more than 90% of the Java projects. The rest of the projects are using Ant or other proprietary build tools.Image: 2020 Java Developer Productivity ReportAs for each project, there might be different reasons why they choose Maven. For many, the biggest benefits of Maven are in how it manages the project and works with dependencies.Back to topMaven vs. GradleWhile both tools are used with the same goal – namely to automatize the application build process – there are still some major differences. While Maven is using an XML (pom.xml) for a project configuration, Gradle has its own domain-specific language (DSL) based on a Groovy (build.gradle) or Kotlin (build.gradle.kts) code. Benefits of Maven vs. GradleMaven BenefitsGradle BenefitsDependency managementOfficial build tool for AndroidPOM – easier to adaptBetter performanceMany plugins availableUsing Groovy/KotlinIDE integrationFlexibility Dependency managementThe fact that Gradle is using programming language may be big pros for some teams. In a head to head performance comparison with Maven, Gradle often dominates in some key areas.Related blog:Making Gradle Builds FasterBack to topMaven vs. AntApache Ant is the predecessor of Apache Maven. First released in 2000, Ant was developed as a replacement for a build tool Make, which was used widely in software development in the past. Using an XML file, Ant is used to automatize build tasks. But, without the addition of the Apache Ivy plugin, Ant doesn’t support dependency management. Benefits of Maven vs. AntMaven BenefitsAnt BenefitsDependency managementFlexiblePOM – easier to adaptNo forced coding conventionMany plugins availableNo forced project structureIDE integration Ant's limitations were the reason why most of the development team later moved to the Maven, which is not only a build tool but a complex tool that helps with software lifecycle management. There are still a number of projects that use Ant as the main build tool, including SAP Hybris.Back to topFinal ThoughtsWithout build tools like Maven or Gradle, developing and maintaining projects would be a painful process. Maven is a great tool that helps not only with building the application but also manages all the dependencies. Gradle is taking a large part of the Java build tool market, and largely focuses on the same functional goal – to manage the build process. The difference is in the way how both tools works. The successful predecessor, Apache Ant, is still there with us but its market share is now really low.If you are about to start a new project and you are considering which tool to use, always check the main features of both tools and choose the one that works the best for you. While Android developers will most likely go with Gradle, as it is a default build tool for Android applications, they can still decide for Maven. Maven has support for plugins and there is an official Android-Maven-plugin that adds support for Maven.Additional ResourcesIf you want to hear some additional discussion on Maven, and where it sits within the Java build tool space, be sure to watch this webinar. It breaks down the results of our 2020 Java developer survey, including commentary on the top technologies being used within Java applications today.If you're looking for more Maven-specific content, the links below are worth checking out.Comparing Gradle, Maven, and AntMaven Options Cheat SheetHow to Speed Up Your Maven BuildToday, streamlining your development processes is more important than ever. So what's one issue that gets in the way of almost every Java developer? Redeploys! If you're ready to skip redeploys and get back to coding, try JRebel. JRebel lets developers skip redeploys and maintains application state so developers can keep doing what they do best, coding amazing Java applications.Try JRebel for FreeBack to top
Pavel Fol Solutions Consultant, JRebel by Perforce Pavel is a Solutions Consultant at JRebel by Perforce. Pavel is passionate about helping Java development teams increase development efficiency with our tools, while providing continued support for ongoing success.