What is Maven?
Maven is an automation and management tool developed by Apache Software Foundation. It was initially released on 13 July 2004. In Yiddish language the meaning of Maven is “accumulator of knowledge”. Maven is a project management and comprehension tool that provides developers a complete build life-cycle framework. Development team can automate the project’s build infrastructure in almost no time as Maven uses a standard directory layout and a default build life-cycle. 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. Maven includes project information and configuration information for Maven such as construction directory, source directory, dependency, test source directory, Goals, plugins, etc.
What are the key features of Maven?
- Simple project setup that follows best practices
- Consistent usage across all projects
- Easy way to build projects in which unnecessary details are hidden
- Uniform build system, where a standard strategy is followed
- Dependency management including automatic updating
- Quality project information, such as dependency lists, cross referenced sources and unit test reports
- Dependency management, including automatic updating and dependency closures
- The ability to handle multiple projects simultaneously
- Dynamic downloading of necessary Java libraries and plug-ins from Maven repositories
- Model-based builds − Maven is able to build any number of projects into predefined output types such as jar, war, metadata
- Coherent site of project information − Using the same metadata as per the build process, maven is able to generate a website and a PDF including complete documentation
- Backward Compatibility – You can easily port the multiple modules of a project into Maven 3 from older versions of Maven. It can support the older versions also
- Parallel builds − It analyses the project dependency graph and enables you to build schedule modules in parallel. Using this, you can achieve the performance improvements of 20-50%.
What are the core concepts of Maven?
- Build Plugins: Build plugins are used to perform specific goal. You can add a plugin to the POM file. Maven has some standard plugins you can use, and you can also implement your own in Java.
- Build Profiles: Build profiles a set of configuration values which allows you to build your project using different configurations. For example, you may need to build your project for your local computer, for development and test. To enable different builds you can add different build profiles to your POM files using its profiles elements and are triggered in the variety of ways.
- POM Files: Project Object Model (POM) Files are XML file that contains information related to the project and configuration information such as dependencies, source directory, plugin, and goals etc. used by Maven to build the project. When you should execute a maven command you give maven a POM file to execute the commands. Maven reads pom.xml file to accomplish its configuration and operations.
- Dependencies and Repositories: Dependencies are external Java libraries required for Project and repositories are directories of packaged JAR files. The local repository is just a directory on your machine hard drive. If the dependencies are not found in the local Maven repository, Maven downloads them from a central Maven repository and puts them in your local repository.
- Build Life Cycles, Phases and Goals: A build life cycle consists of a sequence of build phases, and each build phase consists of a sequence of goals. Maven command is the name of a build life-cycle, phase or goal. If a life-cycle is requested executed by giving maven command, all build phases in that life cycle are executed also. If a build phase is requested executed, all build phases before it in the defined sequence are executed too.
What maven does?
Below are the task performed by Maven:
- We can easily build a project using maven.
- We can add jars and other dependencies of the project easily using the help of maven.
- Maven provides project information (log document, dependency list, unit test reports etc.)
- Maven is very helpful for a project while updating central repository of JAR’s and other dependencies.
- With the help of Maven we can build any number of projects into output types like the JAR, WAR etc without doing any scripting.
- Using maven we can easily integrate our project with source control system (such as Subversion or Git).
Advantages of using Maven:
- Maven can add all the dependencies required for the project automatically by reading pom file.
- One can easily build their project to jar,war etc. as per their requirements using Maven.
- Maven makes easy to start project in different environments and one doesn’t needs to handle the dependencies injection, builds, processing, etc.
- Adding a new dependency is very easy. One has to just write the dependency code in pom file.
Disadvantages of using Maven:
- Maven needs the maven installation in the system for working and maven plugin for the ide.
- If the maven code for an existing dependency is not available, then one cannot add that dependency using maven.
Maven is an automation and management tool. Maven is a popular open source build tool for enterprise Java projects, designed to take much of the hard work out of the build process. Maven uses a declarative approach, where the project structure and contents are described, rather than the task-based approach used in Ant or in traditional make files, for example. This helps enforce company-wide development standards and reduces the time needed to write and maintain build scripts. When you use Maven, you describe your project using a well-defined project object model, Maven can then apply cross-cutting logic from a set of shared (or custom) plugins. In case of multiple development teams environment, Maven can set-up the way to work as per standards in a very short time. As most of the project setups are simple and reusable, Maven makes life of developer easy while creating reports, checks, build and testing automation setups.