Maven Interview Questions

What is Maven?

Maven is a project management tool. It provides the developer a complete build lifecycle framework. On executing Maven commands, it will look for POM file in Maven; it will run the command on the resources described in the POM.

What does it mean when you say Maven uses Convention over Configuration?

Maven uses Convention over Configuration which means developers are not required to create build process themselves. Developers do not have to mention each and every configuration details.

What are the aspects Maven manages?

Maven provides developers ways to manage following:

  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Releases
  • Distribution
  • mailing list

What are the 3 build lifecycle of Maven.

The three build lifecycles are:

  • clean:cleans up artifacts created by prior builds.
  • default (or build):This is used to build the application.
  • site: generates site documentation for the project.

What is POM?

POM stands for Project Object Model. It is fundamental Unit of Work in Maven. It is an XML file. It always resides in the base directory of the project as pom.xml. It contains information about the project and various configuration details used by Maven to build the project(s).

What is Maven artifact?

Usually an artifact is a JAR file which gets arrayed to a Maven repository. One or more artifacts a maven build produces such as compiled JAR and a sources JAR.

Each artifact includes a group ID, an artifact ID and a version string.

List out the dependency scope in Maven?

The various dependency scope used in Maven are:

  • Compile: It is the default scope, and it indicates what dependency is available in the classpath of the project
  • Provided: It indicates that the dependency is provided by JDK or web server or container at runtime
  • Runtime: This tells that the dependency is not needed for compilation but is required during execution
  • Test: It says dependency is available only for the test compilation and execution phases
  • System: It indicates you have to provide the system path
  • Import: This indicates that the identified or specified POM should be replaced with the dependencies in that POM’s section

What are the build phases in Maven?

Build phases in Maven are

  • Validate
  • Compile
  • Test
  • Package
  • Install
  • Deploy

What are the Maven’s order of inheritance?

The maven’s order of inheritance is

  • Parent Pom
  • Project Pom
  • Settings
  • CLI parameters

What is a Maven Repository

A repository is a place i.e. directory where all the project jars, library jar, plugins or any other project specific artifacts are stored and can be used by Maven easily.

What types of Maven repository?

Maven repository are of three types: local, central, remote

What is local repository?

Maven local repository is a folder location on your machine. It gets created when you run any maven command for the first time. Maven local repository keeps your project’s all dependencies (library jars, plugin jars etc).

What is the default location for your local repository?


What is the command to install JAR file in local repository?

mvn install

What is Central Repository?

It is repository provided by Maven community. It contains a large number of commonly used libraries. When Maven does not find any dependency in local repository, it starts searching in central repository using following URL:

What is Remote Repository?

Sometimes, Maven does not find a mentioned dependency in central repository as well then it stops the build process and output error message to console. To prevent such situation, Maven provides concept of Remote Repository which is developer’s own custom repository containing required libraries or other project jars.

What is Archetype?

Archetype is a Maven plugin whose task is to create a project structure as per its template.

What is the command to create a new project based on an archtype?

Type the following command:

mvn archetype:generate

What is transitive dependency in Maven?

Transitive dependency means to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically.

How profiles are specified in Maven?

Profiles are specified using a subset of the elements available in the POM itself.

What is a Mojo?

A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos.