Make, Maven and Gradle
Level 5 · Building the project
What a build tool does, and how it skips work that has not changed. Make with its Makefile, Maven with pom.xml, and Gradle for Java and Android.
Course contentsLesson 12 of 13
Level 1 · The editor
Level 2 · Checking and fixing code
Level 3 · Trying code out
Level 4 · Other people's code
Level 5 · Building the project
After this lesson you can
- Say what a build tool does
- Read a simple Makefile
- Tell Maven from Gradle
13 mincovers 4 glossary entries
Worth reading first: Virtual Environments and uv
What a build tool does, and how the big three differ
A build tool runs the steps that turn your code into a finished program. You write the steps once in a file, and the tool runs them in order: compile, test, then pack it up. Good ones skip any step whose files did not change. Make, the oldest of the best-known three, dates from 1976.
Without one, someone builds by hand, and each person builds in a slightly new way. The copy that works on one laptop fails on the server. With a build tool, each person and each server runs the very same steps.
Make is old and simple. It reads a file called a Makefile, which lists targets, the files each one needs, and the commands that make it. Make compares file dates and rebuilds only what depends on a changed file. It began with C programs, and people now use it to run all kinds of jobs.
Make has one famous trap. Each command line in a Makefile must start with a tab, not spaces. Many editors turn a tab into spaces, and Make then stops with an error about a missing separator.
Apache Maven is a build tool for Java. The whole project is described in one file, pom.xml, which also lists the packages it needs. Maven expects a fixed layout, with code in src/main/java, and runs a set list of phases such as compile, test and package. The result lands in a folder called target.
Gradle is a build tool used most for Java, Kotlin and Android apps. Its steps live in a file called build.gradle.kts, which is code, so you can add steps of your own. It skips work that has not changed, so later builds are fast. Projects ship a small script, gradlew, that fetches the right Gradle version.
The common mistake is running a Gradle you put on your own machine. It may be the wrong version for the project, so use ./gradlew instead. With Maven, the mistake is fighting the layout. Put files where it looks for them, or it will not find your code.
Three build tools side by side
| Tool | Recipe file | Mostly used for |
|---|---|---|
| Make | Makefile | C programs, and any job you can script |
| Apache Maven | pom.xml | Java projects with a fixed layout |
| Gradle | build.gradle.kts | Java, Kotlin and Android apps |
Which one you will meet
app: main.c
cc -o app main.c
test: app
./app --self-testWorked example
The words for this lesson4
Check yourself
Why does Make say missing separator?
Finished this lesson?
Marking it complete also marks its 4 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.