Maven Build Interview Questions

Maven Build Interview Questions and how to answer them in job interview to secure a job.

Q.1 What is Maven and how does it work?
Maven is primarily a project management tool that provides the developer a complete build lifecycle framework.

How it Works
When executing Maven commands, it will look for POM file in Maven; such that it will run the command on the resources described in the POM.q
Q.2 What are the activities handled by Maven?
The activities handled by Maven are -
1. Build
2. Documentation
3. Reporting
4. Dependencies
5. SCMs
6. Releases
7. Distribution
8. Mailing list
Q.3 What are the three build lifecycle of Maven?
The three build lifecycle of Maven are -
1. Clean: Cleans up artifacts that are created by prior builds
2. Default (build): Used to create the application
3. Site: For the project generates site documentation
Q.4 What is POM, in Maven?
In Maven, POM is abbreviated as Project Object Model which is referred as is the fundamental unit of work. This is an XML file which holds the information about the project and configuration details used to build a project by Maven.
Q.5 What do you understand by Maven artifact?
In general an artifact is a JAR file that gets arrayed to a Maven repository. Such that one or more artifacts a maven build produces such as compiled JAR and a sources JAR. Also each artifact includes a group ID, an artifact ID and a version string.
Q.6 What is a Maven Repository and define their types?
Maven repository is referred to as a location where all the project jars, library jars, plugins or any other particular project related artifacts are stored and be easily used by Maven.

Maven repository is of three types namely - local, central and remote.
Q.7 Why do we use Maven Plugins?
We use Maven Plugins because -
1. it creates a jar file
2. It creates war file
3. It compiles code files
4.Assists in unit testing of code
5.Assist in documenting projects
6. Assists in reporting
Q.8 What according to you is the dependency scope in Maven?
The dependency scope used in Maven are -

1. Compile: It is the default scope, and it indicates what dependency is available in the classpath of the project
2. Provided: It indicates that the dependency is provided by JDK or web server or container at runtime
3. Runtime: This tells that the dependency is not needed for compilation but is required during execution
4.Test: It says dependency is available only for the test compilation and execution phases
5. System: It indicates you have to provide the system path
6. Import: This indicates that the identified or specified POM should be replaced with the dependencies in that POM’s section
Q.9 How are profiles specified in Maven?
Profiles are specified in Maven by using a subset of the elements existing in the POM itself.
Q.10 How can you exclude dependency?
We can exclude dependency by using the exclusion element, dependency can be excluded
Q.11 Differentiate between Apache Ant and Maven?
Some of the differences between Apache Ant and Maven are -

1. Ant is a toolbox – Maven is a framework
2. Ant does not have formal conventions like project directory structure – Maven has conventions
3. Ant is procedural; you have to tell to compile, copy and compress – Maven is declarative ( information on what to make & how to build)
4. Ant does not have lifecycle; you have to add sequence of tasks manually – Maven has a lifecycle
5. Ant scripts are not reusable – Maven plugins are reusable
Q.12 What are the two setting files known as and what are their location, in Maven?
The setting files in Maven, are called settings.xml, and the two setting files are located at

1. Maven installation directory: $M2_Home/conf/settings.xml
2. User’s home directory: ${ user.home }/ .m2 / settings.xml
Q.13 What are the build phases in Maven?
Some of Build phases in Maven are -

1. Validate
2. Compile
3. Test
4. Package
5. Install
6. Deploy
Q.14 In Maven, what are the build, source and test source directory for POM ?
The build, source and test source directory for POM are

Build = Target
Source = src/main/java
Test = src/main/test
Q.15 Where can we find the class files when we compile a Maven project?
We can find the class files in the following directory

${basedir}/target/classes/.
Q.16 What would the “jar: jar” goal do in Maven?
jar will not recompile sources as it will just create a JAR from the target/classes directory considering that everything else has been done
Q.17 List the Maven’s order of inheritance.
List of maven’s order of inheritance is,

1. Parent Pom
2. Project Pom
3. Settings
4. CLI parameters
Q.18 What are the minimum required elements for POM ?
Minimum required elements for POM are - project root, modelVersion, groupID, artifactID and version
Q.19 How can you produce execution debug output or error messages?
In order to produce execution debug output we could call Maven with X parameter or e parameter
Q.20 What Is Pom and what Information does it contain?
POM is abbreviated for Project Object Model which is a basic Unit of work in Maven. POM is an XML file which perpetually resides within the base directory of the project as pom.xml. In order to create the project(s), it contains numerous configuration details and data concerning the project employed by maven
POM contains the some of the following configuration information −
project dependencies.
plugins.
goals.
build profiles.
project version.
developers.
mailing list.
Q.21 What does Maven encompasses?
Maven encompasses of project object model
Q.22 What is the difference between Maven and Maven 2?
Maven Lifecycle
Q.23 What is the minimum version of Java needed to run Maven?
1.4
Q.24 Where does profiles are configured in Maven?
profiles are configured in pom.xml
Get Govt. Certified Take Test