PrepPilotPractise free

Maven & Gradle interview questions

Builds, dependencies, versions, multi-module projects

17 questions · mvn · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What are the main phases in the Maven build lifecycle?

The main Maven lifecycle phases are validate, compile, test, package, verify, install, and deploy. Each phase represents a step in building and distributing a project, and plugins can attach goals to these phases.

How do you declare a dependency in Maven?

In Maven, dependencies are declared in the <dependencies> section of the pom.xml file. You specify the groupId, artifactId, and version for each dependency.

How do you run a Gradle task?

You run a Gradle task by executing gradle <task-name> or ./gradlew <task-name> if you're using the wrapper. For example, ./gradlew build runs the build task.

What is the purpose of dependency scopes in Maven?

Dependency scopes in Maven control where a dependency is available, such as during compilation, testing, or runtime. This helps manage classpaths and ensures dependencies are only used where needed.

What is the role of artifact repositories in Java builds?

Artifact repositories store build outputs and dependencies, allowing projects to share and reuse artifacts. Examples include Maven Central, Nexus, and Artifactory.

Intermediate questions

Explain how Gradle's Kotlin DSL differs from Groovy DSL.

Gradle's Kotlin DSL (build.gradle.kts) provides type safety and better IDE support compared to Groovy. It helps catch errors at compile time and makes scripts easier to maintain, especially in large projects.

How does Maven handle transitive dependencies?

Maven automatically resolves transitive dependencies by including dependencies of your dependencies. It uses dependency mediation to select the version closest to the root, but this can lead to conflicts if multiple versions are present.

What is a BOM and how is it used in Maven or Gradle?

A BOM (Bill of Materials) is a special POM that lists dependency versions. In Maven, you import a BOM using <dependencyManagement>, and in Gradle, you can use platform dependencies. This ensures consistent versions across modules.

How do you structure a Maven multi-module project?

A Maven multi-module project has a parent POM with a <modules> section listing child modules. Each module has its own POM but inherits configuration from the parent, allowing shared dependencies and plugins.

How can you make builds reproducible in Maven or Gradle?

To make builds reproducible, I use fixed dependency versions, avoid SNAPSHOTs, and configure plugins to produce deterministic outputs. I also verify checksums and use artifact repositories to ensure consistent dependencies.

How do you scan for dependency vulnerabilities in a Java project?

I use tools like OWASP Dependency-Check for Maven or Gradle, which scan dependencies against known CVEs. These tools can be integrated into CI pipelines to generate reports and fail builds if vulnerabilities are found.

How does Gradle resolve dependency conflicts?

Gradle resolves dependency conflicts using a strategy called 'conflict resolution', which by default selects the highest version. You can customize this behavior with resolution rules or use BOMs for consistency.

How do you add a custom Gradle task using Kotlin DSL?

See the answer in the app, free

Senior questions

Describe how you would debug a dependency conflict in a multi-module Maven project.

See the answer in the app, free

How would you design a Gradle multi-module build for a large microservices project?

See the answer in the app, free

What are the trade-offs between Maven and Gradle for large enterprise builds?

See the answer in the app, free

How do you ensure secure artifact publishing and retrieval in CI/CD pipelines?

See the answer in the app, free

More Java topics