Top 50 interview questions and answers of maven

Posted by

Short Description About maven

Maven, a Yiddish word meaning accumulator of knowledge, began as an attempt to simplify the build processes in the Jakarta Turbine project. There were several projects, each with their own Ant build files, that were all slightly different. JARs were checked into CVS. We wanted a standard way to build the projects, a clear definition of what the project consisted of, an easy way to publish project information, and a way to share JARs across several projects.

A result is a tool that can now be used for building and managing any Java-based project. We hope that we have created something that will make the day-to-day work of Java developers easier and generally help with the comprehension of any Java-based project.

Moving to questions and answers

1. What is Maven?

Answer: Maven is a popular open-source build tool developed by the Apache Group to build, publish, and deploy several projects. It is written in Java and is used to build projects written in C#, Scala, Ruby, etc.

This tool is used to develop and manage any Java-based project. It simplifies the day-to-day work of Java developers and aids them in their projects.

2. What are the phases of a Clean Life Cycle?

Answer: The phases of a clean life cycle include:

  • Pre-clean
  • Clean
  • Post-clean

3.What do Build Life Cycles and phases imply in the basic concepts of Maven?


4. What does Maven help with?

Answer: Maven helps with the following:

  • Apache Maven helps manage all the processes, such as building, documentation, releasing, and distribution in project management.
  • The tool simplifies the process of project building. It increases the performance of the project and the building process.
  • The task of downloading JAR files and other dependencies is done automatically.
  • Maven provides easy access to all the required information.
  • Maven makes it easy for the developer to build a project in different environments, without worrying about the dependencies, processes, etc.
  • In Maven, it is simple to add new dependencies, all you need to do is to write the dependency code in the pom file.

5. What are the phases of a Site Life Cycle?


6. What is a ‘Snapshot’ in Maven?

Answer: Snapshot refers to the version available in the Maven remote repository. It signals the latest development copy. Maven inspects for a new version of Snapshot in the remote repository, for every new build.

The snapshot is updated by the data service team with an updated source code every time to the repository for each Maven build.

7. What are the different elements that Maven takes care of?

Answer: In the process, it takes care of the following:

  • Builds
  • Dependencies
  • Reports
  • Distribution
  • Releases
  • Mailing list

8. What is the difference between ANT and Maven?


9. 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.

10. What types of projects are available in Maven?


  • There are thousands of Java projects provided as templates by Maven.
  • This helps the user, as they no longer have to remember every configuration to set up a particular project.
  • For example Spring Project, Spring MVC, Spring Boot, etc.

11. What is POM?

Answer: Project Object Model (POM) refers to the XML files with all the information regarding project and configuration details.

  • It has the description of the project, information regarding the versioning and configuration management of the project.
  • The XML file is in the project home directory. When we tend to execute a task, Maven searches for the POM in the current directory.

12. Why are Maven Plugins used?

Answer: Maven Plugins are used to:

  • Create a JAR file.
  • Create a WAR file.
  • Compile code files.
  • Unit testing of code.
  • Create project documentation.
  • Create project reports.

13. What is a Maven Archetype?


  • Maven Archetype refers to a Maven plugin entitled to create a project structure as per its template.
  • These archetypes are just project templates that are generated by Maven when any new project is created.

14. What is included in the POM?

Answer: POM contains the following configurations:

  • Dependencies
  • Developers and contributors
  • Plugins
  • Plugin configuration
  • Resources

15. What are the types of Maven Plugins?

Answer: There are two types of Maven Plugins:

  • Build plugins – These plugins are executed during the build and are configured in the element of pom.xml
  • Reporting plugins – These plugins are executed during the stage generation and are configured in the element of the pom.xml.

16. What is the command to create a new project based on an archetype?


  • The command – mvn archetype: generate, is used to create a new project based on an archetype.
  • The command is typed in the command prompt, after navigating to the directory in which the project is residing.

17. What are the minimum required elements for POM?

Answer: The minimum required elements for POM are:

  • project root
  • modelVersion – should be 4.0.0
  • groupId – project’s group id
  • artifactId – artifact (project) id
  • version – version of the artifact

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

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

  • Generating source code.
  • Generating documentation from the source code.
  • Compiling of source code.
  • Packaging of the compiled codes into JAR files.
  • Installing the packaged code in a local repository, server, or central repository.

19. What is the difference between Convention and Configuration in Maven?


20. Why is it said that “Maven uses convention over configuration”?


  • Maven uses convention instead of configuration, due to the fact that the developers only need to create a Maven project. The rest of the structure is automatically created.
  • There are many conventions present in Maven for setting up a project, building the artifacts, releasing the code, and running unit tests.

21. What are the steps to install Maven on Windows?

Answer: To install Maven on Windows, observe the following steps:

  • Download Maven first, and then extract it.
  • In the environment variable, add JAVA_HOME, and MAVEN_HOME.
  • Then, add the environment path in the Maven variable.
  • Lastly, verify the Maven installation by checking its version. The command mvn -version will display the version installed in the system.

22. What is Maven’s order of inheritance?

Answer: The order of inheritance in Maven is:

  • Settings
  • CLI parameters
  • Parent POM
  • Project POM

23. What is meant by the term ‘Dependencies and Repositories’ in Maven?


24. What are the steps to install Maven on Ubuntu?

Answer: To install Maven on Ubuntu, observe the following steps:

  • The primary step is to install Java.
  • Then, download Maven.
  • Configure environment variables JAVA_HOME, M3_HOME, MAVEN_HOME, and PATH.
  • Lastly, verify the Maven installation by checking its version.

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


  • The term goal refers to a specific task that makes it possible for the project to be built and organized.
  • Phases that are a stage in the life cycle define the sequence in which the desired goals are to be accomplished.

26. What does ‘Maven Clean’ imply?


27. What is the command to install JAR files in the Local Repository?


  • mvn install is used to install JAR files in the local repository.
  • To install the JAR manually into the local Maven repository, the following plugin is used: mvn install:install-file-Dfile=.

28. What is a Build Profile?


  • Build profiles refer to the set of configuration values required to build a project using different configurations.
  • Different build profiles are added to the POM files while enabling different builds.
  • A build profile helps in customizing build for different environments.

29. What are the different types of Build Profiles?

Answer: There are three different types of build profiles:

  • Per Project – defined in pom.xml
  • Per User – defined in Maven settings.xml
  • Global – defined in Maven global settings.xml

30. How do you know the version of Maven being used?


31. What is meant by the term ‘System Dependency’?


32. What is the reason for using an Optional Dependency?


  • Optional dependencies are used to decrease the transitive burden of some libraries.
  • These dependencies are used when it is not feasible to divide a project into sub-modules.
  • Some dependencies are only used for a specific feature in the project, and if that feature is not there, then that dependency will not be used.

33. What is Clean, Default, and Site in Maven?

Answer: There are three built-in build life cycles:

Clean: The clean lifecycle looks after project cleaning.
Default: The default lifecycle handles the project deployment.
Site: The site lifecycle refers to the creation of the project’s site documentation.

34. What is a Maven Repository?

Answer: Maven repositories refer to the directories of packaged JAR files that contain metadata. The metadata refers to the POM files relevant to each project. This metadata is what allows Maven to download dependencies.

There are three types of repositories:

  • Local Repository
  • Remote Repository
  • Central Repository

35. What is the ‘Dependency Scope’, and how many types of Dependency Scopes are there?


36. What is meant by ‘Transitive Dependency’ in Maven?


  • Maven avoids the need to find out and specify libraries that the dependencies require, by including transitive dependencies automatically.
  • Transitive dependency says that if X depends on Y and Y depends on Z, then X depends on both Y and Z.

37. How does Maven Architecture work?


38. How can a Maven Build Profile be activated?

Answer: A Maven build profile may be activated in the following ways:

  • Explicitly using command console input.
  • Through Maven settings.
  • Based on environment variables.
  • OS Settings.
  • Present/missing files.

39. What is meant by ‘Dependency Exclusion’?

Answer: The exclusion element is used to exclude any transitive dependency. The concept says if X depends on Y and Y depends on Z, then X can be marked Z as excluded.

40. What is Maven Build Lifecycle?

Answer: Maven lifecycle is a collection of steps that are to be followed, to build a project. There are three built-in build lifecycles:

Default: Handles project deployment.
Clean: Handles project cleaning.
Site: Handles the creation of the project site’s documentation.

41. What is MOJO?

Answer: MOJO can be defined as a Maven plain Old Java Object. Every MOJO is an executable goal in Maven, and a plugin refers to the distribution of such MOJOs. MOJO enables Maven to extend the functionality that is already not found in it.

42. What is the command to produce a new project based on a hard drive?


43. What are the different phases in the Maven Build Lifecycle?


44. What is the Maven settings.xml file?

Answer: The Maven settings.xml file contains elements used to define the values needed to configure Maven execution differently.

It contains the following configurations:

  • Proxy configuration
  • Local repository configuration
  • Remote repository configuration
  • Central repository configuration

45. What is meant by the term ‘Super POM’?


46. Which command is used to build a Maven site?

Answer: mvn site command is used to build a Maven site
The resulting site, by default, is target/site/…

47. What is meant by Maven build lifecycle? Name these cycles.

Answer: A Maven build life cycle comprises of certain phases. It determines the order in which the Maven goals need to be performed. If a particular phase is to be accomplished, then all the previous phases prior to that particular phase need to be run successfully in sequence.

Maven build life cycles are listed below as the followings:

Clean: Removes the artifact produced from the preceding build processes.
Default: Deployment and build process is taken care of.
Site: Project documentation is carried out in this cycle.

48. Where are Maven dependencies stored?


  • All the JARS, dependency files, etc. that are downloaded by Maven are saved in the Maven local repository.
  • The Maven local repository is a folder location on the local system where all the artifacts are locally stored.

49. What are the different conventions used while naming a project in Maven?

Answer: The full name of a project in Maven includes:

: :

For example:

org.apache.maven: maven: 2.0.1

50. What is a Maven Artifact?

Answer: Maven Artifact refers to a file, usually a JAR that gets deployed to a Maven repository. The tool creates one or more artifacts, such as a compiled JAR and a source JAR.

Every artifact has its groupID, an artifact ID, and a version string. These three together identify the artifact. For example:

com.your.package, any name, and a version string (to uniquely identify).

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x