What you'll learn
Real Java projects have dozens of libraries, a compile step, tests, and packaging. Doing that by hand is impossible to reproduce. Build tools — Maven and Gradle — automate all of it and manage your dependencies. Every professional project uses one.
By the end you'll be able to:
- Explain what build tools do and why they matter
- Read a Maven
pom.xmland run its lifecycle - Add dependencies and understand scopes and transitive dependencies
- Recognise a Gradle build script
- Understand multi-module and reproducible builds
Why build tools matter
A build tool solves three problems at once: dependency management (declare a library and the tool downloads it and everything it needs), build automation (compile, test, and package with one command), and reproducibility (anyone, anywhere, gets an identical build). No more hunting for JARs or "works on my machine."
Maven & pom.xml
Maven is convention-based: put your code in the standard folders and it just works. Its heart is pom.xml (Project Object Model) — an XML file declaring your project's identity (the coordinates groupId : artifactId : version) and its dependencies:
<project>
<groupId>com.mastercoding</groupId>
<artifactId>app</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>The Maven lifecycle
Maven runs through a fixed sequence of phases. Running one phase runs all the phases before it — so mvn package automatically validates, compiles, and tests first:
mvn compile # compile the source code
mvn test # compile + run the tests
mvn package # compile + test + build the JAR
mvn install # + install to your local repositoryDependencies & scopes
You declare a dependency by its coordinates; Maven fetches it (and its own dependencies — transitive dependencies) from a central repository. A dependency's scope controls when it's available — for example, test libraries shouldn't ship in your production JAR:
| Scope | Available at | Example |
|---|---|---|
compile | everywhere (the default) | your core libraries |
provided | compile & test, not packaged | a servlet API the server supplies |
runtime | run & test, not compile | a JDBC driver |
test | tests only | JUnit, Mockito |
Mind your dependencies
Gradle
Gradle is the other major build tool — the default for Android. Instead of XML it uses a concise script (Groovy or Kotlin), and it's faster thanks to a build cache and incremental builds. The same two dependencies look like this:
plugins {
id 'java'
}
dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.17.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
}Note
Recap & quick check
Key takeaways
- Build tools automate compile/test/package and manage dependencies reproducibly.
- Maven's pom.xml declares coordinates (groupId:artifactId:version) and dependencies.
- Running a lifecycle phase runs all earlier phases (mvn package also compiles and tests).
- Dependency scope controls availability (compile, provided, runtime, test); deps pull in transitive deps.
- Gradle is script-based and fast (Android's default); both support multi-module builds.
Quick check
1. What is the main file that configures a Maven project?
2. What happens when you run 'mvn package'?
3. What is a transitive dependency?
4. Which scope keeps a library out of the production build?
5. Which build tool is the default for Android?
Great — your projects can now build and manage dependencies professionally. Next up: Module 32 — Git & Professional Java Workflow.