Top 20 Maven Interview Questions | Maven Interview Questions

Below are the Top 20 Maven Interview Questions based on the candidate's experiences and the company's interview pattern.

 

 

1. 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 a POM file in Maven; it will run the command on the resources described in the POM.

 

2. Explain what is POM?

In Maven, POM (Project Object Model) is the fundamental unit of work. It is an XML file that holds the information about the project and configuration details used to build a project by Maven.

 

3. Explain what is Maven artifact?

Usually, an artifact is a JAR file that 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.

 

4. Explain what is Maven Repository? What are their types?

A Maven repository is a location where all the project jars, library jars, plugins, or any other particular project-related artifacts are stored and can be easily used by Maven.

Their types are local, central and remote.

 

5. Explain how you can exclude dependency?

By using the exclusion element, dependency can be excluded

 

6. List out what are the build phases in Maven?

Build phases in Maven are:

1) Validate

2) Compile

3) Test

4) Package

5) Install

6) Deploy

 

7. Where do you find the class files when you compile a Maven project?

You will find the class files ${basedir}/target/classes/.

 

8. For POM what are the minimum required elements?

The minimum required elements for POM are project root, modelVersion, groupID, artifactID, and version.

 

9. Explain how to run test classes in Maven?

To run test classes in Maven, you need a surefire plugin, check and configure your settings in setting.xml and pom.xml for a property named "test."

 

10. What aspects are managed by Maven?

1) Builds

2) Documentation

3) Reporting

4) SCMs

5) Releases

6) Distribution

 

11. Define SNAPSHOT in terms of maven.

The snapshot indicates the current development copy.

 

12. What does the central repository consist of?

It consists of a large number of libraries that are frequently used.

 

13. Mention the phases of the cleaning lifecycle.

The lifecycle of cleaning consists of:

1) pre-clean

2) clean

3) post-clean

 

14. What is the purpose of mvn clean command?

The command removes the target directory before the starting of a build process.

 

15. What is an archetype?

Archetype is the maven plugin. It creates the project structure.

 

16. What are the minimum required elements for POM? 

The minimum required elements for POM are:

1) project root

2) modelVersion – should be 4.0.0

3) groupId – project’s group id

4) artifactId – artifact (project) id

5) version – version of the artifact

 

17. What is meant by the term ‘Build Tool’?

A build tool is essential for the process of building. It is needed for the following procedures:

1) Generating source code.

2) Generating documentation from the source code.

3) Compiling of source code.

4) Packaging of the compiled codes into JAR files.

5) Installing the packaged code in a local repository, server, or central repository.

 

18. What is meant by Maven Plugins?

Maven plugins are essential features of Maven that are used to reuse the common build logic across several projects.

The plugins are needed to carry out tasks like compiling code, testing them, creating JAR files, and documenting the projects.

 

19. What are the types of Maven Plugins?

There are two types of Maven Plugins:

 

1) Build plugins – These plugins are executed during the build and are configured in the <build/> element of pom.xml

2) Reporting plugins – These plugins are executed during the stage generation and are configured in the <reporting/> element of the pom.xml.

 

20. What is the ‘Goal’ in the Maven terminology? 

1) The term goal refers to a specific task that makes it possible for the project to be built and organized.

2) Phases that are a stage in the life cycle define the sequence in which the desired goals are to be accomplished.