Other Build Managers

Steven Zeil

Last modified: Dec 18, 2023
Contents:

make is not the only project build tool that you might encounter.

It is the oldest and most widely known and, messy as it is, probably has the easiest initial learning curve you will encounter. But there are others.

Two in particular that see a lot of use with Java projects are Maven and Gradle.

We won’t teach you here how to write build files for Maven and Gradle, but you should know how to recognize when a project uses them and how to run them if someone has already provided you with a build file.

1 Maven

Maven is a very popular project builder, in part because it is portable. A Maven build works equally well in Linux and in Windows. By contrast, make is pretty much limited to one operating system, simply because a Makefile is written to invoke operating system-specific commands.

Maven is, however, largely limited to Java projects. If you work in other programming languages, you may find Maven difficult or even impossible to use.

1.1 Installed

If you encounter a project that contains a file named pom.xml, that project is intended to be built using Maven.

The usual way to build a Maven project is to cd to the directory containing the pom.xml file and give the command:

mvn package

This assumes that the Maven program mvn is already installed on the machine.

Typically this command results in several actions:

  1. If the project uses code libraries, the libraries are fetched from the Internet and made available.
  2. Your Java code will be compiled.
  3. If the project includes unit tests, those tests will be run.

So a typical Maven “build” actually does a lot more for you than just compile your code.

1.2 Wrapper

If you see that the project not only has a pom.xml file but also files named mvnw and mvnw.cmd, then you can use Maven even if it is not installed on the machine where you are working. The ‘w’ in mvnw stands for wrapper, and the Maven wrapper allows you to run maven without having it installed.

The typical command is

./mvnw package

This command results in several actions:

  1. When run for the first time, it downloads the Maven program as a collection of Java .jar and then runs Maven from one of those jars.
  2. If the project uses code libraries, the libraries are fetched from the Internet and made available.
  3. Your Java code will be compiled.
  4. If the project includes unit tests, those tests will be run.

2 Gradle

Gradle is another popular project builder. Like Maven, Gradle builds are portable across different operating systems. And, although Gradle is particularly popular among Java programmers, its use is not limited to Java. Gradle can handle a much wider variety of programming language projects than Maven.

Gradle is considered the standard build tool for Android programmers.

2.1 Installed

If you encounter a project that contains a file named build.gradle and another named settings.gradle that project is intended to be built using Gradle.

The usual way to build a Gradle project is to cd to the directory containing the settings.gradle file and give the command:

gradle build

This assumes that the program gradle is already installed on the machine.

Typically this command results in several actions:

  1. If the project uses code libraries, the libraries are fetched from the Internet and made available.
  2. Your Java code will be compiled.
  3. If the project includes unit tests, those tests will be run.

The fact that this list is the same as for Maven is no accident. Like Maven, a typical Gradle “build” actually does a lot more for you than just compile your code.

2.2 Wrapper

Like Maven, Gradle has an option to supply a wrapper allowing you to run Gradle without installing it. Gradle offered this wrapper capability well before Maven, and, in my experience, the majority of Gradle projects include the wrapper.

If you see that the project not only has build.gradle and settings.gradle files but also files named gradlew and gradlew.bat, then you can use Gradle even if it is not installed on the machine where you are working.

The typical command is

./gradlew build

This command results in several actions:

  1. When run for the first time, it downloads the Gradle program as a collection of Java .jar and then runs Gradle from one of those jars.
  2. If the project uses code libraries, the libraries are fetched from the Internet and made available.
  3. Your Java code will be compiled.
  4. If the project includes unit tests, those tests will be run.