Maven Interview Questions

What Is Maven?
Maven is a project management and comprehension tool. Maven provides developers a complete build lifecycle framework. Development team can automate the project’s build infrastructure in almost no time as Maven uses a standard directory layout and a default build lifecycle.

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 Managed?
Maven provides developers ways to manage following:

Builds
Documentation
Reporting
Dependencies
SCMs
Releases
Distribution
mailing list

How Do You Know The Version Of Mvn You Are Using?
Type the following command :

mvn –version

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 Information Does Pom Contain?
POM contains the some of the following configuration information −

project dependencies.
plugins.
goals.
build profiles.
project version.
developers.
mailing list.

What Is Maven Artifact?
An artifact is a file, usually a JAR that gets deployed to a Maven repository. A Maven build produces one or more artifacts, such as a compiled JAR and a “sources” JAR.

Each artifact has a group ID (usually a reversed domain name, like com.example.foo), an artifact ID (just a name), and a version string. The three together uniquely identify the artifact. A project’s dependencies are specified as artifacts.

Name 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 Maven Build Lifecycle?
A Build Lifecycle is a well defined sequence of phases which define the order in which the goals are to be executed. Here phase represents a stage in life cycle.

What Is The Command To Quickly Build Your Maven Site?
Type the command− mvn site

What Would The Command Mvn Clean Do ?
This command removes the target directory with all the build data before starting the build process.

What Are The Phases Of A Maven Build Lifecycle?
Following are the phases:−

validate − validate the project is correct and all necessary information is available.
compile − compile the source code of the project.
test − test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package − take the compiled code and package it in its distributable format, such as a JAR.
integration-test − process and deploy the package if necessary into an environment where integration tests can be run.
verify − run any checks to verify the package is valid and meets quality criteria.
install − install the package into the local repository, for use as a dependency in other projects locally.
deploy − done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

What Is A Goal In Maven Terminology?
A goal represents a specific task which contributes to the building and managing of a project. It may be bound to zero or more build phases. A goal not bound to any build phase could be executed outside of the build lifecycle by direct invocation.

What Would This Command Do Mvn Clean Dependency:copy-dependencies Package?
This command will clean the project, copy the dependencies and package the project (executing all phases up to package).

What Phases Does A Clean Lifecycle Consist?
The clean lifecycle consists of the following phases:

pre-clean.
clean.
post-clean.

What Phases Does A Site Lifecycle Consist?
The phases in Site Lifecycle are:−

pre-site
site
post-site
site-deploy

What Is Build Profile?
A Build profile is a set of configuration values which can be used to set or override default values of Maven build. Using a build profile, you can customize build for different environments such as Production v/s Development environments.

What Are Different Types Of Build Profiles?
Build profiles are of three types :

Per Project − Defined in the project POM file, pom.xml.
Per User − Defined in Maven settings xml file (%USER_HOME%/.m2/settings.xml).
Global − Defined in Maven global settings xml file (%M2_HOME%/conf/settings.xml)

How Can You Activate Profiles?
A Maven Build Profile can be activated in various ways −

Explicitly using command console input.
Through maven settings.
Based on environment variables (User/System variables).
OS Settings (for example, Windows family).
Present/missing files.

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

Leave a Reply