Cross_Column

Saturday, 24 January 2026

Maven Interview Questions



Maven Interview Questions and Answers

Maven Interview Questions and Answers

Apache Maven is a popular build automation and dependency management tool mainly used for Java projects. It follows the principle of Convention over Configuration and uses an XML file called pom.xml. Below are the most frequently asked Maven interview questions with clear explanations and examples.


1. What is Maven?

Maven is a build automation tool used to manage a project’s build, dependencies, documentation, and reporting. It simplifies the build process by providing a standard project structure and centralized dependency management.

2. What are the main features of Maven?

  • Dependency Management
  • Standard Project Structure
  • Build Lifecycle Management
  • Plugin-based architecture
  • Central Repository support

3. What is POM?

POM stands for Project Object Model. It is an XML file (pom.xml) that contains project configuration, dependencies, plugins, and build information.


<project>
    <groupId>com.example</groupId>
    <artifactId>demo-app</artifactId>
    <version>1.0</version>
</project>

4. What is Maven Repository?

A Maven repository is a location where project dependencies are stored.

  • Local Repository – Stored on developer’s machine
  • Central Repository – Public repository maintained by Maven
  • Remote Repository – Custom repositories (Nexus, Artifactory)

5. What is Maven Build Lifecycle?

Maven build lifecycle defines the sequence of steps for building and distributing a project.

Default Lifecycle Phases:

  • validate
  • compile
  • test
  • package
  • verify
  • install
  • deploy

6. What happens when you run mvn install?

It compiles the code, runs tests, packages the application, and installs the generated artifact into the local repository.

7. What is Dependency Management?

Dependency management allows Maven to automatically download required libraries from repositories. You only need to define dependencies in pom.xml.


<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version>
    <scope>test</scope>
</dependency>

8. What are Dependency Scopes in Maven?

  • compile – Default scope
  • provided – Provided by container (e.g., Servlet API)
  • runtime – Needed at runtime
  • test – Used only for testing
  • system – Provided manually

9. What is a Maven Plugin?

A Maven plugin is used to perform specific tasks like compiling code, running tests, or creating JAR files.

10. What is the Surefire Plugin?

The Surefire plugin is used to execute unit tests during the test phase.

11. What is Maven Profile?

Maven profiles allow you to define environment-specific configurations such as dev, test, and prod.


<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>development</env>
        </properties>
    </profile>
</profiles>

12. What is the difference between Maven and Ant?

Maven Ant
Convention over configuration Configuration over convention
Dependency management built-in No dependency management
Uses POM Uses build.xml

13. What is SNAPSHOT in Maven?

A SNAPSHOT version represents a project under active development. Maven checks for updated SNAPSHOT versions automatically.

14. How do you skip tests in Maven?


mvn install -DskipTests

15. What is Maven Archetype?

Maven archetype is a project template used to generate a standard project structure.


mvn archetype:generate

16. What is the use of settings.xml?

The settings.xml file is used for configuring proxies, mirrors, credentials, and repositories.

17. Difference between dependencyManagement and dependencies?

  • dependencyManagement – Defines versions centrally
  • dependencies – Actual dependency usage

18. What is the Maven Wrapper?

Maven Wrapper allows projects to use a specific Maven version without installing Maven manually.

19. How does Maven resolve dependency conflicts?

Maven uses the nearest definition strategy, selecting the dependency closest to the project in the dependency tree.

20. Why is Maven important in real projects?

  • Reduces manual dependency handling
  • Ensures consistent builds
  • Improves project maintainability
  • Widely used in CI/CD pipelines

Conclusion

Maven is an essential tool for Java developers. Understanding Maven concepts such as POM, lifecycle, dependencies, and plugins is crucial for cracking interviews and working on real-world projects.

No comments:

Post a Comment

Few More

Maven Interview Questions

Maven Interview Questions and Answers Maven Interview Questions and Answers Apache Maven is a popular build...