Maven — Build System & Dependency Management
Maven is the most widely used Java build tool. It standardises project structure, manages dependencies from Maven Central, and provides a lifecycle (compile, test, package, deploy). Understanding Maven is essential for every Java developer.
pom.xml & Maven Lifecycle
<!-- pom.xml — Maven project descriptor -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.priygop</groupId>
<artifactId>library-system</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- centralise version numbers -->
<jackson.version>2.17.1</jackson.version>
<slf4j.version>2.0.13</slf4j.version>
<junit.version>5.11.0</junit.version>
</properties>
<dependencies>
<!-- JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<!-- Logging API (compile-time) + implementation (runtime) -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.6</version>
<scope>runtime</scope> <!-- not needed at compile time -->
</dependency>
<!-- Database -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.3</version>
</dependency>
<!-- Testing — only in test scope -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Fat JAR with all dependencies (runnable) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.priygop.library.Main</mainClass>
</transformer>
</transformers>
</configuration>
</plugin>
</plugins>
</build>
</project>
<!--
Maven Lifecycle phases (run in order):
validate → check project is correct
compile → compile source code
test → run unit tests (mvn test)
package → create JAR/WAR (mvn package)
verify → run integration tests
install → install to local ~/.m2 repository
deploy → upload to remote repository
Common commands:
mvn clean package clean old output, compile, test, package
mvn clean package -DskipTests skip tests for fast build
mvn dependency:tree visualise dependency tree
mvn versions:display-dependency-updates check for newer versions
-->Quick Quiz
Tip
Tip
Practice Maven Build System Dependency Management in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Continuous Integration & Deployment automates the release process
Practice Task
Note
Practice Task — (1) Write a working example of Maven Build System Dependency Management from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Common Mistake
Warning
A common mistake with Maven Build System Dependency Management is skipping edge case testing — empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready java code.