12. Maven
Programming Project 2021/22

12.1. Introduction

What is Maven?

Maven is a package manager and a build tool for Java.

It is an open source project managed by the Apache Software Foundation.

It was first released in 2004, which means that:

  • It is almost 20 years old!
  • It solves a real problem developers have.
  • It is stable and trustworthy.

Maven is of the most popular build tools for Java, as reported in:

Read more at https://maven.apache.org/what-is-maven.html.

Why Maven?

Maven's main objective is to allow a developer to comprehend the complete state of a development effort in the shortest period of time.

It does that by:

(1) Making the build process easy.

  • Maven will shield you from many details,
  • but it doesn’t eliminate the need to know about the underlying mechanisms.

(2) Providing a uniform build system.

  • Maven builds a project using its project object model (POM) and a set of plugins.
  • If you understand how one Maven project works, you know how all of them work.

(3) Providing quality project information, such as

  • change-log created directly from source control,
  • dependencies used by the project,
  • unit test reports including coverage.

(4) Encouraging better development practices.

  • Standard directory layout.
  • Good testing practices with
    • separate test source code,
    • naming conventions to locate and execute tests,
    • test cases that setup their environment.

What is a package manager?

A package manager is a tool that automates the process of installing, upgrading, configuring, and removing software programs and libraries from a computer system in a consistent manner.

System-level package managers.

Application-level package managers.

You can find a list of package managers here.

Why use a package manager?

  1. We want to reuse someone else's code.
  2. We want to share our work with others.
  3. We don't want to store large binary files in our git repository.
  4. We need help to handle complex dependency trees as projects get more complex.
  5. We want to easily find and download the packages we need.
  6. We want to easily understand which packages (and their specific versions) a project uses. Package managers establish a shared convention for managing libraries.
  7. We want to compartmentalize the installation of dependencies.

StackExchange

What is a build tool?

A build tool is a program that automates the creation of executable applications from source code.

Build automation is the act of scripting tasks that developers do in their day-to-day activities, such as

  • downloading dependencies,
  • compiling source code into binary code,
  • running tests,
  • packaging binary code,
  • deploying to production systems.

Examples of build tools.

You can find a list of build automation tools here.

StackOverflow

Why use a build tool?

In a small project, you may not need one, as you can simply invoke the build process manually. When projects get larger, this is not practical.

  1. We want to keep organized what needs to be built, in what sequence, and the dependencies needed.
  2. We want a quick and consistent build process.
  3. We want easy to build projects.
  4. We want to use our own IDEs.
  5. We want to implement continuous integration and delivery pipelines.

This is how easy it to build a project using Maven.

mvn package

StackOverflow

What is good about Maven?

  1. Quick project setup: convention over configuration.
  2. Modular projects.
  3. Mature dependency management.
  4. Mature project build lifecycle.
  5. Robust plugin community.
  6. Very good IDE support, including IntelliJ IDEA, Eclipse, and VS Code.

What is not so good about it?

  1. The use of XML to describe projects
    • XML is generally disliked due to its hard-to-read syntax.
    • The project description file becomes very big, very quickly.
  2. Maven is harder to extend than Gradle.
  3. Maven is slower than Gradle.

Maven, a de facto standard

Maven established "standards" that are used by other build tools.

  • Maven standard directory layout
  • Artifact naming
  • Artifact repository

Our goal with this module

Our main goal is for you to learn the basic concepts related to package managers and build tools.

A considerable part of this knowledge is transferable to other tools that you may use in the future, such as Gradle, npm, and Grunt.

Understanding Java's build process is valuable for those venturing into the DevOps world.

We do not expect you to be a Maven guru.

You will have to use Maven in your course project.