Agentic AI with Java: Live Cohort
MavenLifecycle, Testing & Spring Boot

Maven WrapUp

A one page revision of the whole Maven course, covering build tool basics, installation, project creation, goals, dependencies, repositories, the POM, IDEs, the lifecycle, testing and Spring Boot.

You started with a simple question (why do we even need a build tool?) and finished by building, testing and running a Spring Boot web application with Maven. This page is the summary note for the whole course. Keep it open the next time you need to revise quickly or debug a build.

What you covered

AreaThe key ideaLesson
Build toolsCompile, test and package automatically, and manage libraries for youWhy and what is build tool
InstallationJDK first, then Maven's bin on PATH. Verify with mvn -vInstalling Maven
Project creationmvn archetype:generate with quickstart (JAR) or webapp (WAR)Maven Java Project
VocabularyArchetype, groupId, artifactId, version, packaging (GAV)Maven Terminologies
Goalsclean, compile, test, package. Each runs the ones before itMaven Goals
DependenciesDeclare libraries in <dependencies>. Maven fetches them and their transitive dependenciesMaven Dependencies
RepositoriesLocal ~/.m2 first, then Central or a company repositoryMaven Repositories
POMCoordinates, properties, dependencies, build pluginsMaven POM.xml file
Effective POMYour POM merged with the Super POM, parents and defaults, in memoryEffective POM
IDEsIntelliJ and Eclipse run the same Maven on the same structureIntelliJ, Eclipse
Lifecycleclean, default and site lifecycles. validate to deployMaven Build LifeCycle Summary
TestingJUnit tests in src/test/java. A failing test fails the buildMaven Java Project Unit Testing
Spring BootInitializr, starter parent, embedded Tomcat, Maven WrapperMaven SpringBoot App Demo

The big picture

How Maven works: pom.xml is read by mvn, which runs plugins and pulls artifacts from the local repository and Maven Central, writing output to target

Command cheat sheet

Create projects
# Standalone Java project (JAR)
mvn archetype:generate -DgroupId=com.telusko -DartifactId=telusko-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.5 -DinteractiveMode=false

# Web project (WAR)
mvn archetype:generate -DgroupId=com.telusko -DartifactId=telusko-web-app -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.5 -DinteractiveMode=false
CommandWhat it does
mvn -vShow Maven version, Maven home and the Java it uses
mvn cleanDelete target/
mvn compileCompile src/main/java to target/classes
mvn testCompile and run unit tests
mvn packageCompile, test and build the JAR or WAR
mvn clean packageFresh build from scratch. The everyday command
mvn verifyPackage plus integration checks. Good default for CI
mvn installAlso copy the artifact into ~/.m2/repository
mvn deployAlso upload it to a remote repository (needs distributionManagement)
mvn dependency:treeShow direct and transitive dependencies
mvn help:effective-pomShow the merged POM Maven really uses
mvn test -Dtest=CalcTestRun one test class
mvn package -DskipTestsBuild without running tests (use with care)
mvn -o packageOffline build from the local repository
./mvnw ... / mvnw.cmd ...Same commands through the project's Maven Wrapper

Mistakes worth remembering

MistakeSymptomFix
Running Maven outside the project folder"there is no POM in this directory"cd into the folder with pom.xml
JAVA_HOME points to bin or a JRE"JAVA_HOME is not defined correctly" or "No compiler is provided"Point it to the JDK root
No Java version in an old POM"Source option 5 is no longer supported"Set maven.compiler.release
{name} instead of ${name}Literal {...} in errorsAlways use ${...}
Dependency pasted outside <dependencies>Imports do not compileMove it inside, reload the IDE
Test class not named *TestTests run: 0Follow Surefire's naming patterns
Fixed version on a library the parent managesVersion conflicts at runtimeRemove the version, let the parent manage it

Where Maven shows up next in the bootcamp

When one of those builds fails, the skills from this course (reading Maven output, checking mvn -v, looking at the dependency tree and the effective POM) are how you find the cause quickly.

Try It Yourself

  1. Without looking at the lessons, create a quickstart project, add spring-core, write one JUnit 5 test, and run mvn clean verify.
  2. Install that project with mvn install and use it as a dependency in a second project.
  3. Add the Maven Wrapper to your project with mvn wrapper:wrapper, then build with ./mvnw clean package (or mvnw.cmd).
  4. Explain to someone else, in under two minutes, what happens when you type mvn package.

Official references


Written By: Shramik Masti

How is this guide?

Last updated on