Transitive Dependencies¶
Dependency of your dependency.
Example:
Project -> Spring Web -> Jackson
You added Spring Web, but Jackson also gets downloaded automatically.
groupId, artifactId, version¶
groupId¶
Organization / company name.
<groupId>org.springframework.boot</groupId>
artifactId¶
Project/library name.
<artifactId>spring-boot-starter-web</artifactId>
version¶
Specific release/version.
<version>3.5.0</version>
Archetype¶
Template project generator.
Example:
mvn archetype:generate
Creates starter structure automatically.
Dependency Scopes¶
Default Scope = compile¶
Available:
-
compile
-
test
-
runtime
Included in final build.
<scope>compile</scope>
Usually omitted because it's default.
provided Scope¶
Needed during compile, but server/container provides it at runtime.
Example:
<scope>provided</scope>
Typical:
Servlet API in Tomcat
Not packaged into final JAR/WAR.
runtime Scope¶
Not needed for compilation.\ Needed only while running app.
Example:
<scope>runtime</scope>
Typical:
Database driver
test Scope¶
Only available during testing.
Example:
<scope>test</scope>
Typical:
JUnit
Mockito
Not included in production build.
Maven Properties¶
Reusable variables/constants inside pom.xml.
Example:
<properties>
<java.version>21</java.version>
</properties>
Usage:
<version>${java.version}</version>
Avoids repeating hardcoded values.
<exclusions> in Dependencies¶
Prevents unwanted transitive dependencies.
Example:
<dependency>
<groupId>org.example</groupId>
<artifactId>demo</artifactId>
<exclusions>
<exclusion>
<groupId>com.bad.library</groupId>
<artifactId>bad-lib</artifactId>
</exclusion>
</exclusions>
</dependency>
Used when:
-
dependency conflicts
-
duplicate versions
-
security issues
-
unnecessary large libraries
Project Object Model (POM)¶
pom.xml = Maven project blueprint/configuration.
Controls:
-
dependencies
-
plugins
-
build lifecycle
-
packaging
-
project metadata
POM Location¶
Located at:
project-root/pom.xml
Maven commands search current directory for pom.xml.
Parent / Super POM¶
Maven supports inheritance.
Super POM¶
Default Maven configuration inherited automatically.
Parent POM¶
Custom shared config across projects.
Example:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
</parent>
<repository>¶
Defines where dependencies are downloaded from.
Default:
Maven Central Repository
Official:\ Maven Central Repository
Structure of POM File¶
1. Project Metadata¶
Project identity/details.
Example:
<name>demo</name>
<version>1.0</version>
<packaging>jar</packaging>
2. Dependencies¶
Libraries project needs.
Example:
<dependencies>
</dependencies>
3. Plugins¶
Extra build tasks/tools.
Example:
-
test reports
-
code analysis
-
executable JAR generation
Maven Lifecycle¶
Validate¶
Checks project structure/config.
Compile¶
Converts source code → .class files.
Output:
target/classes
Test¶
Runs unit tests.
Package¶
Creates distributable artifact.
Example:
JAR / WAR
Verify¶
Runs quality/integrity checks.
Example:
-
static analysis
-
integration checks
Install¶
Stores package in local Maven repository.
Location:
~/.m2/repository
Deploy¶
Uploads package to remote repository.
Used in CI/CD pipelines.
<build> Tag¶
Customize build process.
Example:
<build>
<plugins>
</plugins>
</build>
Used to:
-
add plugins
-
customize phases
-
generate reports
-
package apps
Core Structure of pom.xml¶
1. <project>¶
Root element of POM.
2. Identity¶
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0</version>
Uniquely identifies project.
3. <parent>¶
Inherits shared/default configuration.
4. <properties>¶
Centralized reusable config values.
Example:
<java.version>21</java.version>
5. <dependencies>¶
External libraries required by project.
6. <build> + <plugins>¶
Defines how project is built/executed.
7. Metadata¶
Optional publishing information.
Example:
<name>
<description>
<licenses>
Bottom Line¶
| Section | Purpose |
|---|---|
| Identity | Project identity |
| Parent | Inherited defaults |
| Properties | Shared config values |
| Dependencies | Required libraries |
| Plugins | Build behavior |
Runtime Dependency Example¶
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
Meaning:
-
needed only while app runs
-
not needed for compilation
Maven Wrapper (mvnw)¶
Runs Maven project without globally installing Maven.
Linux/Mac:
./mvnw clean install
Windows:
mvnw.cmd clean install
Why mvnw Matters¶
1. No Maven Installation Needed¶
Project ships its own Maven wrapper.
2. Version Consistency¶
Entire team uses same Maven version.
Avoids:
"Works on my machine"
problems.
3. Auto Download¶
If required Maven version missing:
-
wrapper downloads correct version automatically
-
runs build immediately
Important Real-World Insight¶
Most Maven confusion comes from:
-
not understanding dependency scopes
-
not understanding transitive dependencies
-
randomly copying dependencies from StackOverflow
Strong developers:
-
inspect dependency trees
-
control versions deliberately
-
minimize unnecessary dependencies
Useful command:
mvn dependency:tree
This exposes:
-
transitive dependencies
-
version conflicts
-
duplicate libraries