Skip to content
Ameen Abozaid
BEG-054

Build tools

  • 6 Lessons
  • 61 min of reading
  • 2.5 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Maven basics
  • pom.xml
  • dependencies
  • build lifecycle
  • running tests

Learn first

61 min of reading · 2.5 h of practice (estimate)

Learning outcomes

  1. Explain what a build tool does and why manual javac does not scale.
  2. Read a pom.xml: coordinates, dependencies, and plugins.
  3. Run mvn compile, test, and package and explain the lifecycle phases.
  4. Add a dependency from Maven Central and convert an existing project to Maven.

Lessons

  1. 01Why build tools11 min read
  2. 02Project structure and pom.xml10 min read
  3. 03Dependencies and Maven Central10 min read
  4. 04The build lifecycle10 min read
  5. 05Running tests with Maven10 min read
  6. 06Demo: converting a project to Maven10 min read

Lab and exercises

Lab

BEG-054-LAB1 · Mavenize

Outcomes: 1–4 · Time: ~2.5 h Convert the data-structures project to Maven with JUnit as a test dependency; mvn test passes from the terminal. Acceptance: builds on a clean machine.

Exercises (assessment: practical check)

IDOutcomeTask
BEG-054-EX011List three problems with compiling a ten-library project by hand with javac.
BEG-054-EX022Label groupId, artifactId, version, a dependency, and a plugin in a given pom.xml.
BEG-054-EX032Place five given files into the correct Maven folders.
BEG-054-EX043Run mvn compile, mvn test, and mvn package; say what each produced.
BEG-054-EX053Explain why mvn package also runs the tests.
BEG-054-EX064Add a library from Maven Central and use one class from it.
BEG-054-EX074Make sure target/ is not committed in the converted project.
Show solutions
  • EX01 Long class paths, manual downloads of JARs, no repeatable steps (and no test running).
  • EX02 Coordinates sit at the top; dependencies under <dependencies>; plugins under <build><plugins>.
  • EX03 Main classes in src/main/java; tests in src/test/java; pom.xml at the root.
  • EX04 compile makes classes in target/classes; test runs tests; package creates a JAR in target/.
  • EX05 Lifecycle phases run in order; test comes before package.
  • EX06 Add the <dependency> block, then import its class; Maven downloads it on the next build.
  • EX07 .gitignore contains target/; git status does not show it.

Quiz

Outcomes: O1 why build tools · O2 pom.xml · O3 lifecycle · O4 dependencies and conversion.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1A build tool mainly:O1
  2. 2Manual javac does not scale because:O1
  3. 3Main Java source folder in Maven:O2
  4. 4Test code lives in:O2
  5. 5Which identifies a Maven project?O2
  6. 6mvn test also runs:O3
  7. 7mvn clean does what?O3
  8. 8Dependencies are downloaded from:O4
  9. 9JUnit should have scope:O4
  10. 10Should target/ be committed?O4

Practical part

Practical check: the data-structures project builds and mvn test passes from a clean clone (lab and EX01–EX07). Pass: at least 8 of 10 quiz questions and a build that works on a clean machine.

Common mistakes

Wrong folder layout; committing target/.

Assessment

Practical check.

Career relevance

Maven in depth (JNR-002).

Type to search levels, phases, modules and lessons.