Chaturmind
LearnDSASystem DesignInterview PrepDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth
  • Java Interview Prep

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Java Interview Prep: Fresher to 2 Years

Java Basics, JVM & Memory

  • JDK, JRE, JVM & the main Method — Interview Questions
  • JVM Memory & Garbage Collection — Interview Questions
  • Data Types, Wrapper Classes & Equality — Interview Questions

Object-Oriented Programming

  • Classes, Objects, Packages & Access Modifiers — Interview Questions
  • Inheritance, Composition, this & super — Interview Questions
  • Polymorphism, Overloading & Overriding — Interview Questions
  • Abstraction, Interfaces & Encapsulation — Interview Questions
  • Constructors, Singleton, Anonymous Classes & Immutability — Interview Questions
  • Design Patterns & SOLID Basics — Interview Questions

Strings, Keywords, Exceptions & Serialization

  • Strings, String Pool, StringBuilder & StringBuffer — Interview Questions
  • static & final Keywords — Interview Questions
  • Exceptions, Generics, Enums & Reflection — Interview Questions
  • Serialization & transient — Interview Questions

Collections Framework

  • Collections Framework Basics — Interview Questions
  • HashMap, HashSet & TreeMap Internals — Interview Questions

Multithreading Basics

  • Threads, Synchronization & volatile Basics — Interview Questions

Java 8+ & Stream API

  • Java 8 to Java 21 Features — Interview Questions
  • Stream API Coding Questions (Part 1) — Interview Questions
  • Stream API Coding Questions (Part 2) — Interview Questions

Coding Round Programs

  • Classic Number & String Programs — Interview Questions
  • String & Collection Programs — Interview Questions
  • Array & String Problem Solving — Interview Questions

Spring Framework Core

  • Spring IoC, Dependency Injection & Beans — Interview Questions
  • Spring Injection Types, Scopes, Profiles & WebFlux — Interview Questions

Spring Boot Essentials

  • Spring Boot Fundamentals — Interview Questions
  • Spring Boot Runners, Servers & Configuration — Interview Questions
  • Spring Boot Controllers, Profiles, Actuator & DevTools — Interview Questions
  • Spring Boot Testing, Exceptions & Auto-Configuration — Interview Questions
  • REST APIs, Swagger, Embedded Servers & Key Annotations — Interview Questions

Spring MVC

  • Spring MVC Architecture & DispatcherServlet — Interview Questions
  • Spring MVC Request Mapping & Controllers — Interview Questions
  • Spring MVC Forms, Views & Interceptors — Interview Questions
  • Spring MVC Exceptions, Security & Dependency Injection — Interview Questions
  • Spring MVC Data Binding, Static Resources & Path Variables — Interview Questions
  • Spring MVC i18n, Testing, File Uploads & Scaling — Interview Questions

Hibernate & Spring Data JPA

  • Hibernate & JPA Core Concepts — Interview Questions
  • Hibernate Performance, Mapping & Scenarios — Interview Questions

SQL

  • SQL Basics, Keys, Normalization & Transactions — Interview Questions
  • SQL Joins, Triggers, Procedures, Functions & Indexes — Interview Questions
  • SQL "Difference Between" Questions — Interview Questions
  • SQL Query Writing (Part 1) — Interview Questions
  • SQL Query Writing (Part 2) — Interview Questions

Microservices Basics

  • Microservices, API Gateway & Communication — Interview Questions
  • Service Discovery, Data Consistency & Deployment — Interview Questions
  • Microservices Monitoring, Security & Resilience — Interview Questions

Maven & Git

  • Maven — Interview Questions
  • Git — Interview Questions
Chaturmind
← Java Interview Prep: Fresher to 2 Years

Java Basics, JVM & Memory

  • JDK, JRE, JVM & the main Method — Interview Questions
  • JVM Memory & Garbage Collection — Interview Questions
  • Data Types, Wrapper Classes & Equality — Interview Questions

Object-Oriented Programming

  • Classes, Objects, Packages & Access Modifiers — Interview Questions
  • Inheritance, Composition, this & super — Interview Questions
  • Polymorphism, Overloading & Overriding — Interview Questions
  • Abstraction, Interfaces & Encapsulation — Interview Questions
  • Constructors, Singleton, Anonymous Classes & Immutability — Interview Questions
  • Design Patterns & SOLID Basics — Interview Questions

Strings, Keywords, Exceptions & Serialization

  • Strings, String Pool, StringBuilder & StringBuffer — Interview Questions
  • static & final Keywords — Interview Questions
  • Exceptions, Generics, Enums & Reflection — Interview Questions
  • Serialization & transient — Interview Questions

Collections Framework

  • Collections Framework Basics — Interview Questions
  • HashMap, HashSet & TreeMap Internals — Interview Questions

Multithreading Basics

  • Threads, Synchronization & volatile Basics — Interview Questions

Java 8+ & Stream API

  • Java 8 to Java 21 Features — Interview Questions
  • Stream API Coding Questions (Part 1) — Interview Questions
  • Stream API Coding Questions (Part 2) — Interview Questions

Coding Round Programs

  • Classic Number & String Programs — Interview Questions
  • String & Collection Programs — Interview Questions
  • Array & String Problem Solving — Interview Questions

Spring Framework Core

  • Spring IoC, Dependency Injection & Beans — Interview Questions
  • Spring Injection Types, Scopes, Profiles & WebFlux — Interview Questions

Spring Boot Essentials

  • Spring Boot Fundamentals — Interview Questions
  • Spring Boot Runners, Servers & Configuration — Interview Questions
  • Spring Boot Controllers, Profiles, Actuator & DevTools — Interview Questions
  • Spring Boot Testing, Exceptions & Auto-Configuration — Interview Questions
  • REST APIs, Swagger, Embedded Servers & Key Annotations — Interview Questions

Spring MVC

  • Spring MVC Architecture & DispatcherServlet — Interview Questions
  • Spring MVC Request Mapping & Controllers — Interview Questions
  • Spring MVC Forms, Views & Interceptors — Interview Questions
  • Spring MVC Exceptions, Security & Dependency Injection — Interview Questions
  • Spring MVC Data Binding, Static Resources & Path Variables — Interview Questions
  • Spring MVC i18n, Testing, File Uploads & Scaling — Interview Questions

Hibernate & Spring Data JPA

  • Hibernate & JPA Core Concepts — Interview Questions
  • Hibernate Performance, Mapping & Scenarios — Interview Questions

SQL

  • SQL Basics, Keys, Normalization & Transactions — Interview Questions
  • SQL Joins, Triggers, Procedures, Functions & Indexes — Interview Questions
  • SQL "Difference Between" Questions — Interview Questions
  • SQL Query Writing (Part 1) — Interview Questions
  • SQL Query Writing (Part 2) — Interview Questions

Microservices Basics

  • Microservices, API Gateway & Communication — Interview Questions
  • Service Discovery, Data Consistency & Deployment — Interview Questions
  • Microservices Monitoring, Security & Resilience — Interview Questions

Maven & Git

  • Maven — Interview Questions
  • Git — Interview Questions
HomeLearnJava Interview PrepJava Interview Prep: Fresher to 2 YearsMaven & Git
✓ FreeBeginner· 7 min read

Maven — Interview Questions

What Maven solves, the POM, dependency scopes (compile vs runtime and more), lifecycles vs phases vs goals, repositories, excluding transitive dependencies, speeding up large builds, running builds, mvn clean vs install, and managing dependencies.

Published September 25, 2026


How to use this lesson

Maven questions are short, but precise vocabulary matters: lifecycle vs phase vs goal, and scope. Many prepared answers get "Maven has three lifecycle phases" wrong. Maven has three lifecycles, each made of many phases.

Q1. What is Maven, and what problem does it solve?

Short answer: Maven is a build automation and dependency management tool for Java. It solves three problems:

  • Dependency hell: it downloads libraries, and their transitive dependencies, from repositories, instead of you copying JARs by hand.
  • Inconsistent builds: there's a standard lifecycle (compile, test, package, install, deploy) that works the same on every machine and in CI.
  • Project structure: convention over configuration (src/main/java, src/test/java), so any developer knows where everything is.

Learn it in depth → CI/CD Pipeline Design

Q2. What is a POM file?

Short answer: pom.xml is the Project Object Model, the XML file that describes the project for Maven:

  • its coordinates (groupId:artifactId:version) and packaging (jar, war, pom);
  • its dependencies, and dependencyManagement;
  • its plugins and build settings;
  • properties, profiles, repositories;
  • for multi-module builds, its parent and modules.
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.shop</groupId>
    <artifactId>order-service</artifactId>
    <version>1.4.0-SNAPSHOT</version>
    <properties>
        <java.version>21</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</project>

Key points to cover:

  • Every POM inherits from the super POM, and optionally from a parent (for example spring-boot-starter-parent). mvn help:effective-pom shows the fully merged result.

Q3. What's the difference between compile and runtime dependencies? What scopes exist?

Short answer: A compile-scope dependency (the default) is needed to compile and run the code, and it's on every classpath. A runtime dependency isn't needed to compile, only to run and test. The classic example is a JDBC driver: your code uses javax.sql/JPA interfaces, and the driver is only needed at runtime.

ScopeCompileTestRuntime / packagedExample
compile (default)✅✅✅Spring, Jackson
provided✅✅❌ (the container supplies it)Servlet API in a WAR, Lombok
runtime❌✅✅JDBC drivers
test❌✅❌JUnit, Mockito
importOnly in dependencyManagement, to import a BOMspring-boot-dependencies

Key points to cover:

  • runtime scope stops you accidentally coding against the driver's internal classes.

Q4. Explain Maven's lifecycles and phases.

Short answer: Maven has three built-in lifecycles:

  • clean: removes the previous build output.
  • default (build): from validation through to deployment.
  • site: generates project documentation.

Each lifecycle is an ordered list of phases. Running a phase runs every earlier phase in that lifecycle. The key phases of the default lifecycle, in order:

validate → compile → test → package → verify → install → deploy

Plugin goals are bound to phases, and they do the actual work. For example, compiler:compile is bound to compile, surefire:test to test, and jar:jar to package.

Common trap: saying "Maven has three lifecycle phases: clean, default and site". Those are three lifecycles, and the default lifecycle alone has more than 20 phases.

Q5. What is a Maven repository?

Short answer: A repository stores artifacts (JARs, POMs, plugins), identified by their coordinates. There are three kinds:

  • Local: ~/.m2/repository. A cache on your machine, where mvn install also puts your own builds.
  • Central: the public Maven Central repository.
  • Remote/private: company repositories such as Nexus, Artifactory or GitHub Packages. They host internal artifacts, and proxy or cache Maven Central.

Key points to cover:

  • Maven searches the local repository first, and downloads anything missing from the remotes.
  • SNAPSHOT versions are mutable and re-checked. Release versions are immutable.

Q6. How do you exclude a dependency?

Short answer: Use <exclusions> inside the dependency that pulls in the unwanted transitive dependency.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Key points to cover:

  • Find where a dependency comes from with mvn dependency:tree -Dincludes=groupId:artifactId.
  • To force a version rather than exclude, pin it in <dependencyManagement>.

Q7. How can you speed up the Maven build of a large project?

Short answer:

  • Build in parallel: mvn -T 1C install (one thread per core).
  • Build only what changed: -pl module-a -am builds a module plus the modules it depends on.
  • Skip what you don't need locally: -DskipTests (tests are still compiled), -Dmaven.test.skip=true (skips even compiling them). Never skip tests in CI.
  • Use offline mode (-o) when dependencies are already cached.
  • Use a repository manager (Nexus/Artifactory) close to your CI.
  • Cache ~/.m2 in CI.
  • Enable the Maven build cache extension, or use the Maven Daemon (mvnd).
  • Split slow integration tests into a separate profile or stage.

Q8. How do you run a Maven build?

Short answer: From the directory containing pom.xml, run a phase, for example mvn package (compile, test and create the JAR or WAR in target/), or mvn verify in CI. Use the Maven Wrapper (./mvnw package), so every machine uses the project's pinned Maven version.

./mvnw clean verify                 # full, clean build with tests
./mvnw spring-boot:run              # run a Spring Boot app
./mvnw -pl order-service -am package -DskipTests

Q9. What's the difference between mvn clean and mvn install?

Short answer: mvn clean runs the clean lifecycle, and deletes the target/ directory, meaning all previous build output. mvn install runs the default lifecycle up to install: it compiles, tests, packages, verifies, and then copies the artifact into your local repository (~/.m2), so other local projects can depend on it.

Key points to cover:

  • mvn clean install runs both lifecycles in one command.
  • install is only needed when another local project consumes the artifact. In CI, verify is usually enough, with deploy publishing to the remote repository.

Q10. How do you manage dependencies in a Maven project?

Short answer:

  • Declare the dependencies in <dependencies>, and let Maven resolve the transitive ones.
  • Centralise versions in <dependencyManagement>, or import a BOM (spring-boot-dependencies), so all modules agree on versions.
  • Keep versions in <properties>.
  • Inspect the result with dependency:tree and dependency:analyze (declared but unused, used but undeclared).
  • Keep dependencies patched with tools such as Dependabot or Renovate, and scan them for vulnerabilities (OWASP Dependency-Check, Snyk).

Q11. Explain the Maven lifecycle once more: what exactly runs when you type mvn install?

Short answer: Maven executes, in order, every phase of the default lifecycle up to install: validate, initialize, the source-generation phases, compile, process-classes, test-compile, test (Surefire runs the unit tests), package (builds the JAR), pre-integration-test/integration-test/post-integration-test (Failsafe, if configured), verify, and finally install. Each phase runs whichever plugin goals are bound to it for your packaging type.

Key points to cover:

  • To run a specific goal on its own, name the plugin goal directly: mvn dependency:tree or mvn surefire:test. That runs only the goal, not the lifecycle before it.

Follow-up questions this topic invites — and their answers

Q: What is a SNAPSHOT version? A: A version still in development (1.4.0-SNAPSHOT). Each deploy can overwrite it, and consumers periodically re-download the latest. A release version (1.4.0) is immutable.

Q: How does Maven resolve version conflicts? A: By "nearest definition wins" in the dependency tree. At equal depth, the first declaration wins. <dependencyManagement> overrides both, which is why BOMs are so useful.

Q: What is a multi-module project? A: A parent POM with <packaging>pom</packaging> listing <modules>. It shares configuration and dependency versions, and builds the modules in dependency order (the reactor).

Q: Maven or Gradle? A: Maven is declarative XML, extremely standard, and predictable. Gradle uses a Groovy or Kotlin DSL, with incremental builds and a build cache, so it's faster and more flexible for large or complex builds. Spring Boot supports both equally.

Previous

Microservices Monitoring, Security & Resilience — Interview Questions

Next

Git — Interview Questions

AI Tutor

Lesson: Maven — Interview Questions

Quick actions

AI responses can be inaccurate. Verify critical information.