Top 20 Maven Interview Questions

 


1. What is Maven?

Maven is a build automation or a project management and comprehension tool. It is used by a developer to compile application. It provides a complete build lifecycle framework to the developers.

It is an automated build tool and the development team can easily automate the project’s build infrastructure in almost no time as Maven uses a standard directory layout and a default build lifecycle.

Maven is generally used for various purposes such as documentation, project development, reporting and releases.

2. What is POM in Maven?

POM stands for Project Object Model. It is the basic unit of work in Maven. It is an XML file that always resides in the base directory of the project as “pom.xml”.

It contains the information about the project and various configuration details that are being used by Maven to build the project, such as Project dependencies, plugins, goals, build profiles, Project version, developers, etc.

3. What are the differences between ANT and Maven?

AntMaven
1. ANT is a toolbox.1. Maven is a framework.
2. ANT does not have formal conventions like project directory structure.2. Maven has a convention to place source code, compiled code, etc.
3. ANT is procedural, we have to provide information about what to do and when to do like compile, copy and compress through code.3. Maven is declarative, it has information on what to make and how to build in pom.xml
4. ANT does not have a lifecycle, we have to add sequence of tasks manually4. Maven has a lifecycle
5. ANT scripts are not reusable.5. Maven plugins are reusable.

4. What is the difference between Quality Assurance and Quality Control?

Maven repository is a place or directory where all the project jars, library jars plugins and any other project dependencies or project specific artifacts are stored and that can be easily used by Maven.

It works as a whole library of files that can be easily accessible and can be easily located in our system without any issue and then it can be used by Maven.

5. How many repositories are there in Maven?

There are three types of repositories in Maven. These are as follows:

Local Repository: It is located in our local system. It is created when we run any Maven commands for the first time. In Maven Local Repository we can find all our project’s dependencies like library jars, plugin jars, etc.

Central Repository: Central Repository is provided by Maven community and contains a large collection of commonly used libraries. When any dependency is not found in local repository by Maven, it starts searching it in Central repository using URL- https://repo1.maven.org/maven2/

Remote Repository: Remote Repository is developer’s own custom repository that contains required libraries or other project jars. When Maven does not find a dependency in both local and central repository, it stops the build process and give an error. To prevent this situation, concept of Remote Repository was discovered by Maven.

6. What is Maven Dependency Search sequence?

When Maven build command is executed, it starts looking for libraries dependency in the following sequence:

Step 1: It search the dependency in Local Repository. If dependency is found, it performs the further processing else it moves to next step.

Step 2: It now starts searching it in Central Repository. If dependency is found in Central repository, it is now downloaded to local repository for future reference and performs the further processing. If dependency is not found and remote repositories are mentioned, then it moves to step 4.

Step 3: If a remote repository is not mentioned, then Maven stops processing and throws the error that it is unable to find dependency.

Step 4: If remote repository is mentioned, it search dependency in remote repository. If the dependency is found then it is downloaded to local repository for future reference and performs the further processing , otherwise the processing is stopped by Maven and will throw an error that it is unable to find dependency.

Maven Dependency

7. What are the dependency scope in Maven?

Dependency Scope usually includes all the dependencies as per the current stage of the build.
The various dependency scope used in maven are as follows:

1. Compile: This is the default scope of Maven and it indicates which dependency is available in the classpath of the project.

2. Runtime: This dependency indicates that dependency is not needed for compilation but it is required during execution.

3. Provided: It indicates that dependency is provided by JDK or container or web server at run-time.

4. System: This indicates that we have to provide the system path.

5. Test: It indicates that dependency is available only for the test compilation and execution.

6. Import: It indicates that the specified POM should be replaced with the dependencies in that POM’s section.

8. What is Maven artifact?

Maven artifact is a file, basically a JAR file, that gets deployed to a Maven repository. One or more artifacts, such as a compiled JAR and a sources JAR are being produced by a Maven build.

Each artifact has a group id (generally a reversed domain name), an artifact id (it’s just a name) and a version string. The combination of these three uniquely identifies the artifact. The project’s dependencies are being specified as artifacts.

see more:https://www.devlabsalliance.com/top-20-maven-interview-questions/

Comments

Popular posts from this blog

Docker Basic Commands Cheat Sheet

How to Install JUnit in Eclipse

Docker-Compose Cheat Sheet