Maven is one of the most commonly-used tools for building and managing Java-based projects. The word maven means "accumulator of knowledge" in Yiddish. Maven provides a unified project structure, describes how a project is built, and describes its dependencies. During the build, this tool can start automatic tests and report about the build. It also aims to assist in project workflow, for example, in release and issue management. It is a very powerful build tool.
An important thing about Maven is that it is used in a declarative way, meaning that you describe WHAT should be done instead of HOW to do something. This greatly simplifies project management.
Maven makes the day-to-day work of Java developers easier and generally helps with the comprehension of any Java-based project written in Java, Kotlin, Scala, or other languages. The full list of Maven features can be found here. If you want more background information on Maven you can read The Philosophy of Maven and The History of Maven.
The key concepts
The key features of Maven are as follows:
Project Object Model (POM). Every project using Maven has an XML file called pom.xml. The file contains all the information about the project including its name, version, properties, dependencies, and configuration details Maven uses to build the project.
Convention over configuration. This means that a programmer does not need to configure all possible options; instead, Maven takes unspecified options with default values. A programmer configures only unconventional options in POM.
Dependency management. Maven automatically downloads specified external libraries and solves conflict cases with dependencies. All dependencies are stored in POM. It is possible to declare as many dependencies as you need for a project.
Repositories. Project dependencies can be loaded in the same way from public storages called repositories or the local file system.
Build lifecycle. The process for building and distributing a project is clearly defined and has a sequence of phases such as validation, compilation, testing, packaging, installing, and others. All phases are described in the POM.
Plugins. Maven can be extended by plugins to utilize a number of tools for reporting or the build process. All information about the plugin configurations is stored in the POM.
Downloading and installing Maven
Maven is distributed in several formats. You can download the binary distribution archive (zip or tar.gz) from the official website and unpack this archive somewhere. Alternatively, you may download the source archive if you intend to build Maven yourself.
Also, you can easily generate a Maven project right in IntelliJ IDEA. You can read about it more here.
To install Maven, follow the installation instructions for your operating system.
To verify that the installation has been completed correctly, run the following command:
mvn -versionThe result should look similar to
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T23:33:14+05:00)
Maven home: /opt/apache-maven-3.5.4
Java version: 9.0.1, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-9-oracle
Default locale: en_US, platform encoding: UTF-8
...The versions of Maven and Java may differ; the main thing is that the command works without errors.
Conclusion
To recap, Maven is more than a simple build tool. It provides an infrastructure to build and manage Java projects in a declarative way using the Project Object Model. If you’ve gotten a rough idea of Maven and installed it, then you completed this lesson. In the next topic, we will show you how to create the simplest Maven project.