According to its own website…
Apache Maven is a software project management and comprehension tool […] can manage a project’s build, reporting and documentation from a central piece of information
We will boil that down to the following, though:
Maven is a dependency management and build tool.
What is dependency management?
Code you work on for your courses is often completely self contained, in one or two class files.
You will typically only be importing other classes from the standard library.
In a real world project, though, you will typically be relying on a significant amount of code written by others.
This code will be packaged in jar files which you will need to have available when building and distributing your code.
In the bad old days, this meant:
This may not sound to bad, but on large scale projects, this can be a huge source of problems!
A dependency manager will allow you to provide a small amount of configuration, and it will then handle all of these problems for you in an automated manner.
When we talk about a build tool, we are generically referring to any tool that allows you to provide a configuration (or script), which can then handle all build steps that are necessary to produce your end product.
For instance, you could use a build tool to trigger dependency management, compile your code, execute automated tests, package your compiled code, and more!
A keep theme here is automation.
If our build process is too complicated, we will forget steps and make mistakes.
This will lead to inconsistencies and errors.
Complex manual processes also make it difficult to work with collaborators, because it takes significant work just to get the code running the same on all developer machines.
Instead, we use a clear, precise configuration and feed it to a build tool to guarantee that we have reproducibility anywhere our code is built.
This also allows us to reduce our build process to a single command!
There are usually multiple build tools that can be used for any given programming language, but Maven is one of the most commonly used in the Java world.
You may be interested in becoming familiar with Gradle as well, though.
Maven relies on a configuration called a Project Object Model (POM) file.
Our main concern at this point is how to configure dependencies.
For simple projects, the building works out of the box!
To add a dependency, we simply need to provide the group id, artifact id and version of the library you want to use.
We call these the coordinates of the artifact.
For example, we might add a dependency on a course library like:
<dependencies>
<dependency>
<groupId>edu.murraystate</groupId>
<artifactId>BlobAPI</artifactId>
<version>1.0</artifactId>
</dependency>
</dependencies>
Note that, when you add a dependency, it may also need its own dependencies.
Fortunately, Maven artifacts are packaged with their own POM file, so Maven will go ahead and download all dependencies transitively.
Maven is configured, by default, to pull artifacts from Maven Central, which is a public, centralized artifact repository.
You may, however, need to use custom, private repositories.
<repositories>
<repository>
<id>BlobAPI-mvn-repo</id>
<url>https://raw.github.com/MSUCSIS/csc430-maven/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>