Maven Interview Questions

Maven Interview Questions And Answers

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 standard directory layout and a default build lifecycle.

What are the aspects Maven manages?

Maven provides developers ways to manage following:

  1. Builds
  2. Documentation
  3. Reporting
  4. Dependencies
  5. SCMs
  6. Releases
  7. Distribution
  8. Mailing list

What are the phases of a Maven Build Lifecycle?

PhasesDescription
validatevalidate the project is correct and all necessary information is available
compilecompile the source code of the project.
testtest the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
packagetake the compiled code and package it in its distributable format, such as a JAR
Integration-testprocess and deploy the package if necessary into an environment where integration tests can be run
verifyrun any checks to verify the package is valid and meets quality criteria
installinstall the package into the local repository, for use as a dependency in other projects locally
deploydone in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

 

What is difference between Snapshot and Version?

In case of Version, if Maven once downloaded the mentioned version say data-service:1.0, it will never try to download a newer 1.0 available in repository. To download the updated code, data-service version is be upgraded to 1.1.

In case of SNAPSHOT, Maven will automatically fetch the latest SNAPSHOT (data-service:1.0-SNAPSHOT) everytime app-ui team build their project.

Online Maven Training

What are the advantages of Maven?

  • No need to add jar file in each project
  • Creates right directory structure
  • Builds and deploys the project

What it does?

Maven simplifies the above mentioned problems. It does mainly following tasks.

It makes a project easy to build

It provides uniform build process (maven project can be shared by all the maven projects)

It provides project information (log document, cross referenced sources, mailing list, dependency list, unit test reports etc.)

It is easy to migrate for new features of Maven

Apache Maven helps to manage

  1. Builds
  2. Documentation
  3. Reporing
  4. SCMs
  5. Releases
  6. Distribution

What features should  a build tool have?

A build tool should have:

  1. Compile java code and build jar, war and ear files for deployment and release.
  2. Versioning and dependency management
  3. Run tests and report test results
  4. Run code quality check with Sonar, Checkstyle, Findbugs, etc.
  5. Environment property substitution
  6. Files generations ( wsdl, AspectJ, XSL,etc)
  7. Support for cross platform (UNIX Windows) and IDEs(eclipse, Netbeasn, Intellij)
  8. Proper documentation and support.

What is a transitive dependency in Maven?

Transitive dependency in Maven means that it is not necessary to discover and specify the libraries that our own dependencies require, Maven includes them automatically.

What is the difference between version and SNAPSHOT ? 

Maven will download  always the specified version. In case of SNAPSHOT Maven will download the latest SNAPSHOT.

Maven Interview questions

What is a Mojo?

A mojo is a Maven plain Old Java Object . Mojo is associated with a Maven goal. A custom plugin is a set of related Mojos (or goals) in a single plugin artifact.

What does the Maven command mvn clean do?

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