Top 50 Interview Questions on Maven

1. What Is Maven?

Maven is a project management and comprehension tool. Maven provides developers a complete build lifecycle framework. Development team can automate the project’s build infrastructure in almost no time as Maven uses a typical directory layout and a default build lifecycle.

2. What Are The Aspects Maven Managed?

Maven provides developers ways to manage following:

  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Releases
  • Distribution
  • mailing list

3. What Is Pom?

POM stands for Project Object Model. It is a fundamental Unit of labor in Maven. It is an XML file. It always resides within the base directory of the project as pom.xml. It contains information about the project and various configuration details employed by Maven to create the project(s).

4. What Information Does Pom Contain?

POM contains the a number of the subsequent configuration information −

project dependencies.

  • plugins.
  • goals.
  • build profiles.
  • project version.
  • developers.
  • mailing list.

5. What Is a Maven Artifact?

An artifact may be a file, usually a JAR that gets deployed to a Maven repository. A Maven build produces one or more artifacts, like a compiled JAR and a “sources” JAR.

Each artifact features a group ID (usually a reversed name , like com.example.foo), an artifact ID (just a name), and a version string. The three together uniquely identify the artifact. A project’s dependencies are specified as artifacts.

6. Name The 3 Build Lifecycle Of Maven?

The three build lifecycles are:

  • clean:cleans up artifacts created by prior builds.
  • default (or build):This is employed to create the appliance .
  • site: generates site documentation for the project.

7. What Are Different Types Of Build Profiles?

Build profiles are of three types :

  • Per Project − Defined within the project POM file, pom.xml.
  • Per User − Defined in Maven settings xml file (%USER_HOME%/.m2/settings.xml).
  • Global − Maven global settings xml file (%M2_HOME%/conf/settings.xml).

8. What Is A Maven Repository?

A repository is a place i.e. directory where all the project jars, library jar, plugins or the other project specific artifacts are stored and may be employed by Maven easily.

9. What Types Of Maven Repository?

Maven repository are of three types:

  • local
  • central
  • remote

10. What Is a Local Repository?

Maven local repository may be a folder location on your machine. It gets created once you run any maven command for the primary time. Maven local repository keeps your project’s all dependencies, library jars, plugin jars and more.

11. What Is The Default Location For Your Local Repository?

~/m2./repository.

12. What Is a Central Repository?

It contains an outsized number of commonly used libraries. When Maven does not find any dependency in the local repository, it starts searching in the central repository using the following URL: http://repo1.maven.org/maven2/.

13. What Is a Remote Repository?

Sometimes, Maven doesn’t find a mentioned dependency within the central repository also then it stops the build process and outputs error messages to the console. To prevent such situations, Maven provides a Remote Repository which can be a developers own custom repository containing required libraries.

14. How do you know the version of MVN you use?

Enter the following command –

mvn – version

15. What is a system dependency?

Dependency with reach system is always accessible and is not looked up in the repository; they are regularly used to tell Maven about dependencies that are provided by the JDK. So, system dependencies are mainly useful for resolving dependencies on artefacts that JDK usually provides.

16. What is the Maven Build lifecycle?

A Build Lifecycle can be defined as a well-defined sequence of phases. It clearly defines the order in which the goals are to be executed. Each build phase contains a sequence of goals. If one life cycle is executed, all build phases in that life cycle are executed. If a build phase is executed, all build phases before it in the predefined sequence of build phases are executed.

17. What is the command to build your Maven site?

Type the command − mvn site

18. What would the command mvn clean do?

This command deletes the target directory with all the build data before starting the build process.

19. What are the different phases of a Maven Build Lifecycle?

Following are the phases of Maven build lifecycle −

validate − validate the project and check if everything is correct and all necessary information is available.

compile − this phase compiles the source code of your project.

test − tests the compiled source code by using a suitable unit testing framework. These tests should not require the code to be packaged or deployed

package − takes the compiled code and packages it in its distributable format.

integration-test − processes and deploys the package if possible into an environment where integration tests can be run.

verify − runs any checks to verify the package is valid and meets the required quality criteria.

install − installation of the package into the local repository. This is done to use it as a dependency in other projects locally.

deploy − wiped out an integration environment or release environment. Here the ultimate package is copied to the remote repository for sharing with other developers and projects.

20. What’s a goal in Maven terminology?

A goal represents a selected task that contributes to the building and managing of a project. it’s sure to zero or more build phases. A goal that’s not sure to any build phase might be executed outside of the build lifecycle by invoking it directly.

21. What are the uses of Maven Plugins?

Maven Plugins are wont to −

  • create a jar file.
  • create a war file.
  • compile code files.
  • unit testing of code.
  • create project documentation.
  • create project reports.

22. What are the kinds of Maven Plugins?

Maven provides the subsequent two sorts of Plugins −

Build plugins −They inherit picture during the build and will be configured within the element of pom.xml

Reporting plugins −They get executed during the location generation and that they should be configured within the element of the pom.xml

23. What is SNAPSHOT in Maven?

SNAPSHOT are often defined as a special version that indicates a current development copy. Unlike the regular versions, Maven checks for a replacement SNAPSHOT version in its remote repository. Maven does it for each build.

24. What is the difference between Snapshot and Version?

In the case of Version, if Maven once downloads the mentioned version say data-service:1.0, it’ll never attempt to download a more modern 1.0 available within the repository. To download the updated code, the data-service version is then upgraded to 1.1.

In the case of SNAPSHOT, Maven will automatically fetch the newest SNAPSHOT (data-service:1.0-SNAPSHOT) whenever the team builds its project.

25. Mention the difference between Apache Ant and Maven?

Apache Ant and Maven

Ant may be a toolbox – Maven may be a framework

Ant doesn’t have formal conventions like project directory structure – Maven has conventions

Ant is procedural; you’ve got to inform to compile, copy and compress – Maven is declarative ( information on what to form & the way to build)

Ant doesn’t have lifecycle; you’ve got to feature sequence of tasks manually – Maven features a lifecycle

Ant scripts aren’t reusable – Maven plugins are reusable

26. For POM what are the minimum required elements?

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

27. Explain the way to run test classes in Maven?

To run test classes in Maven, you would like the surefire plugin, check and configure your settings in setting.xml and pom.xml for a property named “test.”

28. What’s the dependency scope? Name all the dependency scope?

Dependency scope typically includes dependencies as per the present stage of the build. the varied Dependency scopes are −

compile − This scope indicates that dependency is out there within the classpath of the project. it’s the default scope.

provided − this means that the dependency is to be provided by JDK or web-Server/Container at runtime.

runtime − This scope tells that you simply don’t need dependency for compilation but you would like it for execution.

test − This scope states that the dependency is merely available for the test compilation and execution phases.

system − This scope indicates that you simply must provide the system path.

import − This scope is merely used when the dependency is of type pom. This scope tells that the required POM should get replaced with the dependencies within the POM’s section.

29. How are you able to activate profiles?

A Maven Build Profile are often activated within the following ways −

  • Explicitly using command console input.
  • Through maven settings.
  • Based on environment variables (User/System variables).
  • OS Settings (for example, Windows family).
  • Present/missing files.

30. What phases does a Clean Life Cycle consist of?

The clean life cycle consists of the subsequent phases −

  • pre-clean
  • clean
  • post-clean

31. What phases does a Site Lifecycle consist of?

The phases in Site Lifecycle are −

  • pre-site
  • site
  • post-site
  • site-deploy

32. Explain how you can exclude dependency?

Through utilizing the separation element, the dependency can be eliminated

33. In Maven what are the two setting files called and what is their location?

The setting files are called settings.XML, and the 2 more setting files are placed at

  • Users home directory : ${ user.home }/ .m2 / settings.xml
  • Maven installation directory: $M2_Home/conf/settings.xml

34. Explain what would the “ jar” goal do?

jar won’t recompile sources; it’ll imply just create a JAR from the target/classes directory considering that everything else has been done.

35. List out what are the Maven’s order of inheritance?

The maven’s order of inheritance is

  • Parent Pom
  • Project Pom
  • Settings
  • CLI parameters

36. What is MOJO?

It stands for Maven plain Old Java Object. Each MOJO is an executable goal in Maven, and a plugin may be a distribution of 1 or more related MOJOs.

37. What are the main features of Maven?

Some of the main features of Maven are:

Simple: Maven gives easy project settings that support genuine practices.

Fast: You can receive a fresh project or module beginning in fewer seconds in Maven.

Easy to find out : Maven usage and commands are easy to learn across all projects. Therefore ramp-up time for brand spanking new developers coming onto a project is extremely less.

Dependency management: gement: Maven provides superior dependency management including automatic updates and transitive dependencies.

Multiple Projects: you’ll easily work on multiple projects at an equivalent time by using Maven.

Large Library: Maven features a large and growing repository of libraries and metadata to use out of the box.

Extensible: Maven supports the power to simply write plugins in Java or scripting languages for extending its core functionality.

Instant: Maven is online and it provides instant access with very less configuration to new features.

38. What is the difference between compile and install?

Compile compiles the source code of the project whereas

Install installs the package into the local repository, to be used as a dependency in other projects locally

39. Difference between Maven Project and Module?

Maven Module has a Parent whereas Project doesn’t. For the pom file when we add the parent section, it adds the module section to the parent project pom file. When we execute mvn compile/install, it basically checks that module section of the parent to spot all the modules that require it to be compiled first.

40. What is the POM packaging in Maven?

Pom packaging is easily a stipulation that the initial artifact is not a battle or container, through the pom.xml itself.

41. What is a cyclic dependency?

A has a dependency on B, B has a dependency on C and C has a dependency of A.

With Maven 2, came transitive dependency wherein within the above scenario, C will act as a dependency of A as if this dependency has been defined directly during a but the negative side is that if it leads to cyclic dependency, it creates problems.

42. What is a Test Dependency Scope in Maven?

It indicates that the dependency isn’t required for normal use of the appliance , and is simply available for the test compilation and execution phases. This scope is not transitive.

43. What is a Maven dependency?

When maven is run on project B version 1.0 of artifacts a, b, c, and d are going to be used no matter the version laid out in their pom. a and c both are declared as dependencies of the project so version 1.0 is employed thanks to dependency mediation. Both also will have runtime scope since it’s directly specified.

44. What does Maven dependency plugin do?

Apache Maven Dependency Plugin. The dependency plugin provides the potential to control artifacts. It can copy or unpack artifacts from local or from remote repositories to a specified location.

45. What is meant by a goal in Maven?

Executing a phase means executing all previous phases. Plugin is a collection of goals. Plugin is a class and goals are methods within the class. Maven is predicated round the central concept of a build lifecycle.

46. Where are Maven dependencies stored?

The maven local repository may be a local folder that’s wont to store all of your project’s dependencies (plugin jars and other files which are downloaded by Maven). In simple, once you build a Maven project, all dependency files are going to be stored in your Maven local repository.

47. What is a maven assembly?

The maven Assembly Plugin is primarily intended to permit users to aggregate the project output alongside its site documentation, dependencies, modules, and other files into one distributable archive.

48. Why should we use Maven?

Maven may be a powerful project management tool that’s supported POM (project object model). It is used for projects documentation, dependency and build. Maven repository may be a directory of packaged JAR files with pom.xml file. Maven searches for dependencies in the repositories.

49. What are the main advantages of Maven?

Maven features a long list of benefits for Software development.

Some of the main advantages are:

Common Project Structure: Every developer features a common project structure that helps in understanding the code and also as develop new features during a new project.

Modular Design: Maven promotes modular design that divides a posh project into multiple modules that are easier to manage. By using Maven, it’s easier to manage multiple modules for build, test, release etc.

Centralized Dependency Management: With Maven, each developer doesn’t need to include the jars separately in each project or module. Maven provides a centralized dependency management which will help improve efficiency of software development.

Fewer Decisions: With Maven a developer has got to make fewer decisions about things unrelated to software development work. The project structure comes ready with Maven, dependency management may be a uniform approach and build/release are handled by Maven. So a developer can specialise in core work of developing software.

50. What is Super POM?

Super POM in Maven’s default POM. All the POM files extend from Super POM.

Add a Comment

Your email address will not be published. Required fields are marked *