Build Tools, Maven & Jenkins (CI/CD) Guide


1. What is a Build Tool?

A Build Tool automates software development activities such as:

Popular Build Tools

Build Tool Language
Apache Maven Java
Apache Ant Java
Gradle Java
npm JavaScript
pip Python

2. What is Continuous Integration (CI)?

Continuous Integration (CI) is the practice of automatically building and testing code whenever developers commit changes to a repository.

CI Workflow

Developer Commit
        ?
Git Repository
        ?
CI Tool Triggered
        ?
Build Application
        ?
Run Tests
        ?
Generate Reports
        ?
Deploy (Optional)

Benefits of CI

Benefit Description
Early Bug Detection Find issues quickly
Faster Feedback Immediate build results
Automated Testing Less manual effort
Improved Quality Better code stability
Faster Releases Supports Continuous Delivery

3. Build Tool vs CI Tool

Feature Build Tool CI Tool
Purpose Build Application Automate Development Pipeline
Compile Code Yes Uses Build Tools
Run Tests Yes Triggers Tests Automatically
Download Dependencies Yes No
Create JAR/WAR Yes Uses Build Tool
Scheduling No Yes
Source Code Monitoring No Yes
Pipeline Management No Yes
Deployment Automation Limited Yes
Examples Maven, Gradle, Ant Jenkins, GitLab CI, GitHub Actions

4. Maven vs Jenkins

Feature Maven Jenkins
Type Build Tool CI/CD Tool
Purpose Build & Manage Java Projects Automate Build, Test & Deployment
Dependency Management Yes No
Build Automation Yes Triggers Build Tools
Test Execution Yes Via Build Tools
Pipeline Support No Yes
Scheduling No Yes
Source Control Integration Limited Extensive
Deployment Automation Limited Yes
Plugin Ecosystem Moderate Extensive
User Interface Minimal Web Dashboard
Monitoring No Yes
Reporting Build Reports Pipeline Reports
Language Support Primarily Java Multiple Languages

5. Maven Architecture

pom.xml
   ?
Compile
   ?
Test
   ?
Package
   ?
Install
   ?
Deploy

Maven Lifecycle Phases

Phase Purpose
validate Validate Project Structure
compile Compile Source Code
test Execute Unit Tests
package Create JAR/WAR
verify Run Quality Checks
install Install Artifact in Local Repository
deploy Deploy Artifact to Remote Repository

Common Maven Commands

Command Purpose
mvn clean Remove Previous Build Files
mvn compile Compile Source Code
mvn test Run Unit Tests
mvn package Create JAR/WAR
mvn install Install Artifact Locally
mvn deploy Deploy Artifact
mvn clean install Most Common Command

6. Jenkins Core Concepts

Concept Description
Job Build Configuration
Pipeline CI/CD Workflow
Node / Agent Machine Executing Jobs
Controller (Master) Manages Pipelines
Workspace Build Directory
Plugin Adds Functionality
Build Trigger Automatically Starts Builds

7. How Maven and Jenkins Work Together

Developer Pushes Code
          ?
GitHub Repository
          ?
Jenkins Triggered
          ?
mvn clean install
          ?
JUnit Tests
          ?
SonarQube Analysis
          ?
Docker Image Build
          ?
Deploy to Kubernetes

Responsibilities

Activity Maven Jenkins
Compile Code ? ?
Download Dependencies ? ?
Create JAR ? ?
Monitor Git Changes ? ?
Schedule Builds ? ?
Trigger Maven Build ? ?
Pipeline Execution ? ?
Deployment Limited ?

8. Maven Dependency Example


<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

9. Jenkins Pipeline Example


pipeline {

    agent any

    stages {

        stage('Build') {
            steps {
                sh 'mvn clean install'
            }
        }

        stage('Test') {
            steps {
                sh 'mvn test'
            }
        }

        stage('Deploy') {
            steps {
                sh 'docker build -t app .'
            }
        }
    }
}

10. Interview Questions & Answers

Question Answer
What is Maven? Maven is a build and dependency management tool primarily used for Java projects. It automates compiling, testing, packaging, and dependency management using the pom.xml file.
What is Jenkins? Jenkins is an open-source CI/CD tool used to automate software build, testing, code analysis, and deployment pipelines.
Difference Between Maven and Jenkins? Maven builds the application, while Jenkins orchestrates and automates the entire CI/CD process. Jenkins often executes Maven commands such as mvn clean install.
How do Maven and Jenkins work together? Jenkins monitors source code repositories and triggers Maven builds automatically whenever code changes occur.
What is pom.xml? The Project Object Model (POM) file contains project configuration, dependencies, plugins, build settings, and metadata.
What is CI/CD? CI/CD stands for Continuous Integration and Continuous Delivery/Deployment. It automates build, testing, and deployment activities.

Key Takeaway

Maven builds the application.

Jenkins automates when and how the application gets built, tested, analyzed, packaged, and deployed.

In modern DevOps environments, Jenkins commonly invokes Maven commands such as:
mvn clean install
to build Java applications automatically as part of a CI/CD pipeline.