Maven interview questions and answers for Java and build engineers

Maven interview questions check whether you understand what happens when you type `mvn verify`: which lifecycle phases run, which plugin goals are bound to them, how the POM's dependencies, scopes and inherited settings turn into a classpath, and why the version of a library you never declared ended up in the build. Expect definitions first, then dependency conflict puzzles, multi-module questions and a broken CI build to diagnose.

By Published 8 min read

Where Maven questions come up

Maven is still the default build tool in many Java shops, so it appears in Java and Spring developer interviews, in build and release engineering loops, and in DevOps rounds that touch CI pipelines. Developer interviews stay close to the POM, scopes and dependency conflicts. Build and platform roles go further into repository managers, multi-module performance, release versioning and reproducibility. The Java language side lives in Java developer interview questions, and Spring's starters and plugin are covered in Spring Boot interview questions.

Fundamentals: the POM, coordinates and lifecycles

Questions for freshers and first rounds
QuestionWhat it testsWhat a strong answer shows
What is a POM?BasicsThe Project Object Model file, pom.xml, which declares the project's coordinates, packaging, dependencies, plugins and inherited settings. Maven builds from it by convention rather than from a script.
What are Maven coordinates?IdentitygroupId, artifactId and version (GAV), plus packaging and an optional classifier. Together they name one artifact in any repository.
Name the three built-in lifecycles.Lifecyclesdefault (build and ship), clean (remove output) and site (generate project documentation).
What runs when you type mvn package?PhasesEvery phase of the default lifecycle up to package: validate, compile, test and the phases between them, then package. Phases are ordered steps, not standalone commands.
Phase, plugin and goal: how do they relate?Execution modelA plugin provides goals (for example compiler:compile). Goals are bound to phases, by packaging defaults or by your POM. Running a phase runs the goals bound to it and to all earlier phases.
What is the difference between install and deploy?Repositoriesinstall copies the artifact into the local repository on your machine. deploy uploads it to a remote repository so other builds can use it.
What is the standard directory layout?Conventionsrc/main/java, src/main/resources, src/test/java, src/test/resources, with output in target. Following it means almost no configuration.
What is the effective POM?InheritanceThe POM after merging parents, profiles and defaults. mvn help:effective-pom shows it, which is the first step when a setting seems to come from nowhere.
What does packaging pom mean?AggregationThe project produces no jar. It exists as a parent for shared settings, as an aggregator listing modules, or as a BOM.
Why use the Maven Wrapper?Consistencymvnw downloads and runs the Maven version the project specifies, so every developer and CI agent builds with the same tool version.
Questions for freshers and first rounds. Scroll sideways on a small screen.

Dependencies, scopes and conflicts

Intermediate questions that most candidates get partly wrong
QuestionWhat a strong answer shows
Explain compile, provided, runtime and test scope.compile (the default) is on every classpath and passed on to dependents. provided is needed to compile but supplied by the runtime, such as a servlet API in an application server. runtime is needed to run but not to compile, such as a JDBC driver. test exists only for test compilation and execution.
Which scopes are transitive?compile and runtime dependencies of your dependencies come through. provided and test dependencies of a dependency do not, which is why a library's test framework never lands in your build.
Two libraries need different versions of the same artifact. Which wins?Maven keeps one version: the one nearest to your project in the dependency tree. At equal depth, the one declared first wins. The highest version does not automatically win, which surprises many people.
How do you force a version?Declare it directly in your POM or, better, in dependencyManagement. A managed version applies to that artifact wherever it appears in the tree.
dependencyManagement versus dependencies?dependencyManagement only sets versions (and optionally scope) for later use; it adds nothing to the classpath. dependencies actually adds artifacts, and can omit the version when it is managed.
What is a BOM and how do you use one?A bill of materials is a POM of managed versions. Import it in dependencyManagement with type pom and scope import. Unlike a parent, you can import several.
What do exclusions and optional dependencies do?An exclusion cuts one transitive artifact out of a dependency's tree. Marking your own dependency optional means projects that depend on you will not inherit it.
How do you see why a jar is on the classpath?mvn dependency:tree, filtered with -Dincludes=group:artifact, shows every path to it, which is where a surprising version usually explains itself.
What is a SNAPSHOT version?A moving development version. Maven checks remote repositories for newer snapshots according to the update policy, and -U forces a check. Releases are immutable.
Intermediate questions that most candidates get partly wrong. Scroll sideways on a small screen.
from collections import deque

# Each artifact's declared dependencies, in declaration order (a toy repository).
POMS = {
    "app:1.0":        [("web-lib", "2.0"), ("report-lib", "3.1")],
    "web-lib:2.0":    [("http-core", "4.1"), ("json-lib", "1.2")],
    "report-lib:3.1": [("json-lib", "1.5")],
    "http-core:4.1":  [("json-lib", "1.6")],
    "json-lib:1.2": [], "json-lib:1.5": [], "json-lib:1.6": [],
}


def resolve(root, managed=None):
    """Nearest definition wins; at equal depth, the first one declared wins.
    Versions in `managed` (dependencyManagement) override transitive ones."""
    managed = managed or {}
    chosen = {}
    queue = deque([(root, [])])
    while queue:                                  # breadth first = shallowest first
        node, path = queue.popleft()
        for name, version in POMS[node]:
            if name in chosen:
                continue                          # a nearer or earlier declaration already won
            version = managed.get(name, version)
            chosen[name] = (version, " > ".join(path + [name]))
            queue.append((f"{name}:{version}", path + [name]))
    return chosen


for name, (version, via) in resolve("app:1.0").items():
    print(f"{name:10} {version}   via {via}")
print("managed:", resolve("app:1.0", {"json-lib": "1.6"})["json-lib"][0])
# web-lib    2.0   via web-lib
# report-lib 3.1   via report-lib
# http-core  4.1   via web-lib > http-core
# json-lib   1.2   via web-lib > json-lib
# managed: 1.6
A toy model of Maven's version mediation: breadth-first, nearest wins, first declaration breaks ties, managed versions override. The app ends up with json-lib 1.2, the oldest of three candidates, until dependencyManagement pins it.
  • What does a NoSuchMethodError at run time usually mean in a Maven project? Code was compiled against one version of a library and runs with another, typically because mediation picked an older transitive version. Find it with the dependency tree and pin the right one.
  • How do you stop conflicts from creeping back? The Enforcer plugin's dependency convergence rule fails the build when two paths ask for different versions, which forces an explicit decision.
  • What is the difference between `-DskipTests` and `-Dmaven.test.skip=true`? The first compiles tests but does not run them. The second skips compiling them too, which can break modules that depend on another module's test jar.

Repositories, settings and profiles

  • Where does Maven look for artifacts? The local repository first (by default under .m2/repository in your home folder), then the remote repositories in the POM and settings, starting with Maven Central unless a mirror redirects everything.
  • What goes in settings.xml rather than the POM? Machine and user details: mirrors, server credentials, proxies and the local repository path. Credentials never belong in a POM that is committed.
  • Why do companies run a repository manager such as Nexus or Artifactory? It proxies and caches public repositories, hosts internal artifacts, gives one place to block or audit libraries, and keeps builds working when the public internet is slow.
  • What is a mirror? A settings entry that sends requests for one or all repositories to another URL, usually the company's repository manager.
  • What is a profile and how is it activated? A block of POM settings applied only when active: by -P name, a property, the JDK version, the operating system or the presence of a file. Overusing profiles makes builds differ between machines, so keep them few.
  • How do properties and `${project.version}` help? Properties keep repeated values in one place. Using ${project.version} for sibling modules keeps a multi-module build on one consistent version.

Multi-module builds and plugins

<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example.shop</groupId>
  <artifactId>shop-parent</artifactId>
  <version>1.4.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <modules>
    <module>shop-domain</module>
    <module>shop-api</module>
  </modules>

  <properties>
    <maven.compiler.release>21</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <platform.version>4.2.0</platform.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <!-- A BOM: imports a curated set of versions without becoming the parent -->
      <dependency>
        <groupId>com.example.platform</groupId>
        <artifactId>platform-bom</artifactId>
        <version>${platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.example.shop</groupId>
        <artifactId>shop-domain</artifactId>
        <version>${project.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <pluginManagement>
      <plugins>
        <!-- Unit tests run in the test phase, integration tests (*IT) in integration-test/verify -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <executions>
            <execution>
              <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
A parent POM for a two-module project: modules listed once, versions centralized through an imported BOM and the parent's own version, and failsafe set up for integration tests. Plugin versions and the BOM coordinates are placeholders; pin real versions in a real build. Not executed as a build here.
Questions about the reactor, plugins and tests
QuestionWhat a strong answer shows
Parent versus aggregator?A parent passes settings down through inheritance. An aggregator lists modules so one command builds them all. One POM often does both, but they are separate ideas, and a module can inherit from a parent that does not list it.
What is the reactor?The part of Maven that collects all modules, sorts them by their dependencies on each other and builds them in that order.
How do you build only what you changed?-pl selects modules, -am also builds what they depend on, -amd builds what depends on them, and -rf resumes from a failed module.
pluginManagement versus plugins?pluginManagement configures versions and settings for children to use. plugins actually applies the plugin to this project.
Surefire versus Failsafe?Surefire runs unit tests in the test phase and fails fast. Failsafe runs integration tests in integration-test and checks results in verify, so teardown in post-integration-test still runs before the build fails.
How do you build a runnable fat jar?The Shade or Assembly plugin, or the Spring Boot plugin's repackage goal for Boot apps. Mention relocation when shaded libraries could clash with the host's.
How do you speed up a large Maven build in CI?Cache the local repository between runs, build in parallel with -T, build only affected modules, run offline (-o) when everything is cached, and keep slow integration tests in a separate stage.
What makes a Maven build reproducible?Pinned plugin versions, no version ranges, a wrapper-pinned Maven, a fixed output timestamp property for archive entries, and the same JDK everywhere.
Questions about the reactor, plugins and tests. Scroll sideways on a small screen.

Senior and scenario questions

  • The build passes on your laptop and fails in CI with a missing artifact. Something exists only in your local repository: an installed snapshot of a sibling project, or a dependency fetched through a mirror CI cannot reach. Reproduce with a clean local repository and check the mirror and credentials in CI's settings.
  • Two teams publish the same snapshot version and builds become flaky. Snapshots are mutable, so the last upload wins. Give each branch its own version or switch to release versions produced by CI for anything shared.
  • How would you release a library? Move from snapshot to a fixed version, tag, build and test once, deploy that exact artifact, then bump to the next snapshot. The Release plugin automates this; many teams instead set the version from CI and keep the POM on a placeholder.
  • A security scanner flags a vulnerable transitive library. Find the paths with the dependency tree, upgrade the direct dependency that brings it if possible, otherwise pin a fixed version in dependencyManagement, then run the tests and the scanner again.
  • When would you choose Gradle over Maven? For builds that need real logic, faster incremental builds or Android. Maven's strength is a predictable, declarative model that every Java developer can read; switching costs a migration and new conventions.
  • How do you share build rules across fifty repositories? A company parent POM for plugin configuration and a BOM for library versions, both versioned and released like any other artifact, plus Enforcer rules for the non-negotiables.

Fictional example

Answering "Why did upgrading one library break JSON parsing?"
Interviewer
We bumped our HTTP client and now a JSON class throws NoSuchMethodError in production. Nobody touched the JSON library. What happened?
Candidate
Most likely the new HTTP client declares a different JSON library version, and it now sits nearer to our project in the tree than the path that used to supply the newer one, so mediation picked an older version at run time. I would run mvn dependency:tree -Dincludes for the JSON artifact before and after the bump to see both paths. The fix is to manage the JSON version explicitly in dependencyManagement or import the vendor's BOM, then add the Enforcer convergence rule so the next conflict fails the build instead of reaching production. I would also add a test that exercises that JSON call path.

How to prepare for Maven interview questions

  1. Read your own effective POMTake a project you know and trace where each plugin and version comes from. It turns vague answers into specific ones.
  2. Create a conflict on purposeAdd two dependencies that need different versions of one library, inspect the tree, then fix it with dependencyManagement.
  3. Build a three-module projectPractice -pl, -am and -rf, and add failsafe integration tests.
  4. Explain the lifecycle aloudFrom validate to deploy in a minute, including where tests run and what install changes.
  5. Prepare one build storyA slow or broken build you fixed, the commands you used and what you changed. Related reading: Jenkins interview questions and low-level design interview questions, where you will want a project skeleton that builds on the first try.

Build questions reward precise vocabulary, and saying phase when you mean goal is easy under pressure. Natively, an AI interview assistant for Mac and Windows, transcribes your mock interviews on the computer so you can catch those slips afterwards, and it can propose answers live while you rehearse. During practice, screenshot a dependency tree or a failing build log and it can read it and suggest where the conflict is. With Pro or the free trial it draws on the résumé and job description you provide, and the transcript and notes are saved for review.

Questions people ask

What Maven questions are asked in interviews?

The POM and coordinates, the default, clean and site lifecycles, phases versus goals, dependency scopes, how version conflicts resolve, dependencyManagement and BOMs, settings.xml and mirrors, multi-module reactor builds, Surefire versus Failsafe and CI troubleshooting.

How does Maven resolve dependency version conflicts?

It keeps the version nearest to your project in the dependency tree, and at equal depth the one declared first. It does not pick the highest version, so pin important versions in dependencyManagement.

What is the difference between dependencyManagement and dependencies?

dependencyManagement only declares versions and defaults for later use and adds nothing to the classpath. The dependencies section actually adds artifacts to the build.

What is the difference between mvn install and mvn deploy?

install puts the built artifact into your local repository for other local builds. deploy uploads it to a remote repository so other machines and teams can use it.

Where to go next

Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.

Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.

Keep reading

Put it on your own machine.

A live-conversation assistant that runs locally. Your conversations stay on your machine.

macOS 12+ · Windows 10/11

© 2026 Natively AI Private Limited

Source-available under the Natively Personal Use Source License v1.0 · IP geolocation by DB-IP