In this article, we will cover 56 most frequently asked maven interview questions and answers. If you are a developer or programmer then you must be aware of maven tool as it is very frequently used by multiple organizations for Project building and management purpose. Thus making it a very hot Interview topic. Here we will go through all important maven interview questions and answers that can be asked in any technical interview. More on Maven docs.
Maven Interview Questions and Answers
1. What is Maven ?
Ans. Maven is an open source build automation tool from Apache Foundation. It can be used to build, compile and deploy projects developed on different languages like Java, C#, Ruby, Scala etc.
2. What is POM ?
Ans. A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project.
3. What is Super POM ?
Ans. The Super POM is Maven's default POM. All POMs extend the Super POM unless explicitly set, meaning the configuration specified in the Super POM is inherited by the POMs you created for your projects.
4. Which Maven command can be used to compile Application Sources ?
Ans. mvn compile
5. Which is the top level element in all Maven pom.xml files ?
6. Which maven command is used to run unit tests ?
Ans. mvn test
7. What are the minimum requirement for a POM ?
Ans. Below are the minimum requirements:-
8. Which prefix is used to reference all the variables in Maven ?
9. What is Archetype ?
Ans. Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made.
10. How to Create a New Project based on archetype ?
Ans. mvn archetype:generate
11. Which goal search a repository for archetypes and updates a catalog ?
12. Which library can be best used to deal with the specification of local repository, remote repository, developer workspaces, artifact transports, and artifact resolution ?
Ans. Apache Maven Artifact Resolver
13. Does Doxia supports markup languages ?
14. In which format Maven JXR produces documentation ?
Ans. HTML Format
15. Where does Maven search POM file by default ?
Ans. It will search in Project Home directory.
16. What will happen if maven does not find dependencies on your local repository ?
Ans. It will search and download from central repository to local repository.
17. What are different phases in Maven Life Cycle ?
Ans. Below are the different phases in Maven Life Cycle:-
- 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
- verify - run any checks on results of integration tests to ensure quality criteria are met
- install - install the package into the local repository, for use as a dependency in other projects locally
- deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects
18.What are different built-in lifecycles in Maven ?
Ans. There are three different built-in life cycles:-
- default : the main life cycle as it's responsible for project deployment
- clean : to clean the project and remove all files generated by the previous build
- site : to create the project's site documentation
19. What are different advantages of Maven ?
Ans. Below are the different advantages of using Maven:-
- Maven helps manage all the processes such as building, documentation, releasing and distribution in Project Management.
- Maven can be used in different environments to build, compile and deploy the project.
- Maven can deploy multiple projects at once.
- It can automatically download jar files and other dependencies.
20. What are different types of Maven Repositories ?
Ans. There are three different types of Maven Repositories:-
- Local Repository
- Central Repository
- Remote Repository
21. What does Local Repository usually contains ?
Ans. It contains all the dependency jars.
22. Can we use the dependencies directly from Remote Repository ?
Ans. No, We need to first download it to the local repository to use.
23. What are the main differences between Ant and Maven ?
Ans. Below are the main differences between Ant and Maven :-
|Ant is only a project build tool.||Maven can not only build the project but it can compile and deploy the project as well.|
|Ant scripts are not reusable.||Maven Plugins are reusable.|
|Ant does not have any Life Cycle||Maven has a build Life Cycle|
|Ant is Procedural||Maven is Declarative|
24. What is Maven Central Repository ?
Ans. It is basically a Maven community which works together in developing dependencies which is not currently not available on Local Repository.
25. Which maven command builds the project and packages them into a jar or war file ?
Ans. mvn package
26. Which maven command validates all the project details ?
Ans. mvn validate
27. How to create dependency tree of a maven project ?
Ans. Using mvn dependency:tree command
28. What is Goal in Maven ?
Ans. Goal in maven refers to a specific task which needs to be accomplished to build and manage the Projects.
29. What are Phases in Maven ?
Ans. Phases in Maven denotes each of the stages involved in a Build Life Cycle.
30. How to Skip tests while installing or packaging a Project ?
Ans. By using -DskipTests option
31. How to run maven commands in a debug mode ?
Ans. By using -X option
32. What are the different Phases in Clean Lifecycle ?
Ans. Below are the different phases in Clean Lifecycle:-
33. What Should be the order of Inheritance in Maven ?
Ans. The Order of Inheritance in Maven will be:-
- CLI Parameters
- Parent POM
- Project POM
34. How many kinds of Plugins are there in Maven ?
Ans. There are basically two types of plugins in Maven:-
- Build plugins which are executed during the build and configured in the <build/> element.
- Reporting plugins are executed during the site generation and configured in the <reporting/> element.
35. Which element in a POM file indicates the unique name of artifacts generated by a Project ?
36. Which element in a POM file indicates the location of Project's site ?
37. What are Maven Plugins ?
Ans. Plugins are basically the extension of Maven functionality that can be implemented in multiple projects to accomplish a specific task.
38. Which element in POM file indicates the unique identifier of the Organization or group that created the Project ?
39. What is the meaning of "convention over configuration" design philosophy which maven uses ?
Ans. Convention over configuration means developers does not need to create build process by themselves, it will taken care by Maven.
40. What are different types of dependencies in Maven ?
Ans. There are two different types of dependencies in Maven :-
41. What are Direct dependencies in Maven ?
Ans. The dependencies which are exclusively included in the Project are known as Direct Dependencies.
42. What is Transitive dependency in Maven ?
Ans. Transitive Dependency means if X depends on Y and Y depends on Z then X depends on both Y and Z.
43. What is MOJO ?
Ans. MOJO is known as Maven Plain Old Java Object. It is basically an executable goal in Maven.
44. What is Build Profile in Maven ?
Ans. A Build profile is a set of configuration values which is used to set or override default values of Maven build.
45. What are different types of Build Profiles in Maven ?
And. There are three types of Build Profiles in Maven:-
- Per User/Developer
- Per Project
46. Which element indicates the version of the object model a specific POM is using ?
47. Which element indicates the display name used for the Project ?
48. Which maven command detects the unused declared and used undeclared dependencies in a Project ?
Ans. mvn dependency:analyze
49. Which maven command generates a site for the Project ?
Ans. mvn site:site
50. What is Packaging in Maven ?
Ans. Packaging is basically the final end product or artifact maven produces after complete build lifecycle.
51. What are different types of packaging Maven supports ?
Ans. By default, maven supports multiple type of packaging like jar, war, pom, ear, rar, ejb etc.
52. What is Snapshot in Maven ?
Ans. Snapshot is basically the latest temporary development copy of the project available in remote repository.
53. Which command is used to run maven build in offline mode ?
Ans. mvn -o package
54. Which command runs maven build in quiet mode ?
Ans. mvn -q package
55. Which command is used to run parallel build using thread count ?
Ans. mvn -T <count> package
56. Which command is used to compile the Java source classes ?
Ans. mvn compiler:compile