Register Login

Maven Interview Questions and Answers

Updated Apr 10, 2019

What is Maven?

Maven is a software developed by Apache for the purpose of project management and comprehension. It is based on the concept of the project object model or POM, which means that Maven can manage the entire process of building, reporting and documentation a project starting from a fundamental piece of information.

What are the various aspects managed by Maven?

The various aspects of a project that Maven can manage are:

  • Build
  • Documentation
  • Reporting
  • Dependencies
  • SCM
  • Releases
  • Distribution
  • Mailing list

What is Maven repository?

Maven repository is the record that stores the project jars, library jars, plugins and all other particulars of any project related artefacts which can be easily used by Maven later.

List out various types of maven repository?

There are three types of Maven repository:

  • Local
  • Central
  • Remote

How to check Maven version?

The syntax to check the Maven version is mvn –v or mvn –version.

What is GroupId and ArtifactId in Maven?

In Maven, groupId is used to identify a project separately from all other projects by following Java's package naming conventions. Therefore, the project needs a naming schema that begins with a reversed domain name within the user’s control.

In Maven, artifactId refers to the name of the jar without mentioning the version. The user is free to choose a name with all alphabets in the lowercase and without using special symbols.

What is GAV in Maven?

GAV, in Maven, refers to undisputable value class that characterises the coordinates of a unique artefact.

What is POM in Maven?

In Maven, POM stands for Project Object Model. It is an XML file that forms the basic unit in Maven on which the work is done. It stores all the information related to a project as well as the configuration details that Maven uses to build the project. POM givens Maven all the requisite data and configuration information needed to execute a given goal.

How to add a dependency in Pom.xml?

The steps to add a dependency in pom.xml are-

  • Open Window and click on Show View.
  • Click on Other.
  • In Maven, click on Maven Repositories.
  • Right-click on Global Repositories and click on Go Into.
  • Right-click on "central" and choose "Rebuild Index".
  • After indexing is over, right-click on the project.
  • Click on Maven and then on Add Dependency.
  • Type in the project’s name you wish to import.

What is an archetype in maven?

In Maven Archetype is a project tool used to create templates from a model or pattern to derive all the other components of a similar kind. It is basically a system that helps authors to generate Maven projects systematically with the help of a template.

What is a Snapshot in Maven?

Snapshot is a special version of Maven that designates a copy of the current development in a project that is stored in the remote repository. Maven refers to this SNAPSHOT version for every build.

How to add maven plugin in Jenkins?

The steps to add Maven plugin in Jenkins are:

  • On the home screen of Jenkins, click on Manage Jenkins.
  • Select the Configure
  • In the Maven, section click on Add Maven.
  • Uncheck the option to Install automatically.
  • Add the name of the setting.
  • Add the location of MAVEN_HOME.
  • Click on Save.

Explain the basic differences between Ant and Maven?

The differences between Ant and Maven are as follows:

Ant

Maven

It is a toolbox.

It is a framework.

It has no formal conventions such as project directory structure.

It has formal conventions such as project directory structure.

It is a procedural toolbox that needs instructions to compile, copy and compress.

It follows a declarative structure.

It does not have a build lifecycle. Instead, it accepts manual instructions relating to the sequence of tasks.

It has a build lifecycle made of build phases.

Scripts in Ant are not reusable.

Plugins in Maven are reusable.

What is Maven dependency?

A dependency in Maven is a plugin that facilitates manipulation of artefacts. It enables copying and unpacking artefacts from a given local or remote repository to a specific location.

How to add a dependency in Maven?

The steps to add a dependency in pom.xml are:

  • Open Window and click on Show View.
  • Click on Other.
  • In Maven, click on Maven Repositories.
  • Right-click on Global Repositories and click on Go Into.
  • Right-click on "central" and choose "Rebuild Index".
  • After indexing is over, right-click on the project.
  • Click on Maven and then on Add Dependency.
  • Type in the project’s name you wish to import.

Explain maven build lifecycle?

A Build Lifecycle in Maven is a definite series of steps that give definition to the order of execution of goals. It is made of build phases that typically include prepare-resources, validate, compile, test, package, install, and deploy.

What are the types of Maven plugins?

The types of plugins in Maven are:

  • Build plugins, configured within the <build/> element to execute the build process.
  • Reporting plugins, configured within the <reporting/> element to execute at the time of generation of the site.

Explains build phases in Maven?

Build phases denotes a stage in the build lifecycle of a task in Maven. Maven executes them in a specific sequence to attain the completion of the default lifecycle. The phases that make up a typical build lifecycle are prepare-resources, validate, compile, test, package, install, and deploy.

What is mojo in Maven?

A mojo in Maven refers to an Old Java Object in the form of an executable goal that provides the functionality that is not present in Maven.

Explains Goal in Maven?

In Maven, a goal is a task that helps to the build and manages of a project, bound to zero or more than zero build phases. A goal may be executed outside a build lifecycle in case it is not bound to any by means of a direct call. The sequence of execution of goals varies with the order of invocation.


×