Apache Maven – Complete Tutorial

Apache Maven is a powerful build automation and dependency management tool widely used in Java, Selenium, TestNG, Spring Boot, and CI/CD projects.

← Back to Training

1. What is Maven?

Apache Maven is a project management and build automation tool that helps developers manage project builds, dependencies, documentation, and releases.

2. Why Maven?

3. Installing Maven

mvn -version

4. Maven Project Structure

project-name
 ├── src
 │   ├── main
 │   │   ├── java
 │   │   └── resources
 │   └── test
 │       ├── java
 │       └── resources
 ├── pom.xml
 └── target

5. pom.xml Explained

Basic pom.xml

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.prakura</groupId>
  <artifactId>automation</artifactId>
  <version>1.0</version>
</project>

6. Dependency Management

<dependencies>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.20.0</version>
  </dependency>
</dependencies>

7. Dependency Scopes

8. Maven Build Lifecycle

mvn clean install

9. Maven Plugins

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>3.2.5</version>
</plugin>

10. Maven Profiles

<profiles>
  <profile>
    <id>qa</id>
  </profile>
</profiles>
mvn test -Pqa

11. Repositories

12. Maven with Selenium & TestNG

mvn test

13. Maven in CI/CD (Jenkins)

mvn clean test

14. Interview & Real-Time Usage