1οΈβ£ What is Maven?

Maven is a build automation and project management tool used primarily for Java and Spring Boot applications.
π― Problems Maven Solves
- Build generation (compile, test, package)
- Dependency resolution (automatic download & versioning)
- Standard project structure
- Plugin-based extensibility
- Reproducible builds
π§ Core Concept
Maven is declarative, not procedural:
- You describe WHAT you want (in
pom.xml) - Maven decides HOW to do it (via lifecycle + plugins)


![]()
β Quick Summary
- Maven automates build + dependency management
- Uses pom.xml as a single source of truth
- Essential for Spring Boot & enterprise projects
β Interview / Exam Questions (with Answers)
- What is Maven?
β A build and dependency management tool for Java projects. - Why is Maven declarative?
β Developers define configuration, not execution steps. - What problem does Maven solve compared to Ant?
β Dependency management and standard lifecycle.
2οΈβ£ pom.xml β Project Object Model
The pom.xml file is the heart of a Maven project.
πΉ Mandatory Project Coordinates
| Tag | Meaning |
|---|---|
| groupId | Organization / package namespace |
| artifactId | Project name |
| version | Build version |
| packaging | jar / war |
<project>
<groupId>com.javadoor</groupId>
<artifactId>learning-springboot</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
</project>
πΉ Dependency Management (Internal Working)
- Maven downloads dependencies from Maven Central
- Stores them in ~/.m2/repository
- Uses transitive dependencies automatically
β οΈ Edge Case:
Conflicting versions β solved using dependency mediation (nearest-wins).



β Quick Summary
pom.xmlcontrols dependencies, plugins, lifecycle- Enables reproducible builds
- Supports multi-module projects
β Interview / Exam Questions
- What is pom.xml?
- How does Maven resolve version conflicts?
- What are transitive dependencies?
3οΈβ£ Maven Standard Project Structure
Maven enforces Convention over Configuration.
π Default Layout
project
βββ pom.xml
βββ src
βββ main
β βββ java
β βββ resources
βββ test
βββ java
π Why This Matters
- IDEs auto-detect structure
- CI/CD pipelines rely on it
- Reduces onboarding time



β Quick Summary
- Enforced by Maven
- Separates production & test code
- Improves maintainability
β Interview / Exam Questions
- Why does Maven enforce a directory structure?
- Where are compiled classes stored?
- Where are test cases placed?
4οΈβ£ Maven Build Lifecycle
Maven lifecycle = ordered phases executed sequentially.
π Default Lifecycle Phases
| Order | Phase | Purpose |
|---|---|---|
| 1 | validate | Validate project |
| 2 | compile | Compile source code |
| 3 | test | Run unit tests |
| 4 | package | Create JAR/WAR |
| 5 | verify | Quality checks |
| 6 | install | Local repo |
| 7 | deploy | Remote repo |
π Key Rule:
Running a later phase executes all previous phases automatically.



β Quick Summary
- Lifecycle is strictly ordered
- Prevents incomplete builds
- Core Maven concept for interviews
β Interview / Exam Questions
- What happens when you run
mvn package? - Can phases be skipped?
- Difference between lifecycle and goal?
5οΈβ£ Validate Phase (mvn validate)
πΉ Purpose
- Ensures:
- Project structure is correct
- pom.xml is valid
- No compilation happens
πΉ Real-World Use
- Enforce Checkstyle
- Enforce PMD rules
- Enforce license checks



β Quick Summary
- First lifecycle phase
- Ensures correctness before build
- Extensible using plugins
β Interview / Exam Questions
- Does validate compile code?
- Why use validate phase?
- Can plugins run in validate?
6οΈβ£ Compile Phase (mvn compile)
πΉ What Happens Internally
- Uses maven-compiler-plugin
- Converts
.javaβ.class - Output stored in:
target/classes
βοΈ Performance Consideration
- Incremental compilation supported
- Faster in CI with dependency caching
πΌοΈ Required Diagram / Image
Type: Compilation Flow Diagram
Labels must contain:
- Source Code
- Compiler Plugin
- target/classes
Explains:
How Maven compiles Java code.



β Quick Summary
- Compiles only main code
- No tests executed
- Generates bytecode
β Interview / Exam Questions
- Where does Maven store compiled classes?
- Which plugin compiles Java code?
- Does mvn compile run tests?
7οΈβ£ Test Phase (mvn test)
πΉ Purpose
- Executes unit tests
- Uses:
- JUnit
- TestNG
- Stops build if any test fails
π§ Edge Case
- Integration tests are NOT run here (handled separately)
πΌοΈ Required Diagram / Image
Type: Testing Flow Diagram
Labels must contain:
- Test Classes
- JUnit
- Test Results
Explains:
How Maven executes unit tests.



β Quick Summary
- Ensures code correctness
- Mandatory for CI pipelines
- Build fails on test failure
β Interview / Exam Questions
- What happens if a test fails?
- Which tests run in mvn test?
- Difference between test and verify?
8οΈβ£ Package Phase (mvn package)
πΉ Purpose
- Creates JAR / WAR
- Combines:
- Compiled code
- Resources
- Metadata
π¦ Output Location
target/*.jar
πΌοΈ Required Diagram / Image
Type: Packaging Diagram
Labels must contain:
- Compiled Classes
- Resources
- JAR/WAR
Explains:
How Maven builds deployable artifacts.



β Quick Summary
- Produces final artifact
- Used in deployment pipelines
- Executes previous phases automatically
β Interview / Exam Questions
- What is created in mvn package?
- Difference between jar and war?
- Where is the package stored?
9οΈβ£ Install Phase (mvn install)
πΉ Purpose
- Installs artifact into local repository
~/.m2/repository
πΉ Why Important
- Enables multi-module projects
- Allows reuse across local builds
πΌοΈ Required Diagram / Image
Type: Repository Diagram
Labels must contain:
- Project
- Local Repository
- Installed Artifact
Explains:
How Maven installs artifacts locally.



β Quick Summary
- Makes artifact reusable
- Local-only operation
- Required before deploy
β Interview / Exam Questions
- Where does mvn install store artifacts?
- Why is install required before deploy?
- What is local repository?
π Deploy Phase (mvn deploy)
πΉ Purpose
- Uploads artifact to remote repository
- Nexus
- Artifactory
- Maven Central
π Configuration
- Repository in
pom.xml - Credentials in
settings.xml
πΌοΈ Required Diagram / Image
Type: Deployment Architecture Diagram
Labels must contain:
- Local Repository
- Remote Repository
- pom.xml
- settings.xml
Explains:
How Maven deploys artifacts to remote repositories.
![]()


β Quick Summary
- Final lifecycle phase
- Used in enterprise CI/CD
- Publishes artifacts
β Interview / Exam Questions
- Difference between install and deploy?
- Where are credentials stored?
- Can deploy run without install?
π― FINAL CONCLUSION
- Maven is mandatory knowledge for Spring Boot
- Lifecycle understanding is frequently tested
- pom.xml mastery separates junior vs senior engineers
If you want next:
- β PDF export
- β Microservices-specific Maven notes
- β Interview cheat sheet (1-page)
- β CI/CD Maven pipeline explanation
Just tell me.