Skip to main content

Command Palette

Search for a command to run...

Java Series #9: Web Foundations, Build Tools, and Automation β€” A Clear Breakdown

Build Automation in Java β€” A Clear Guide to Maven & Gradle

Published
β€’5 min read
Java Series #9: Web Foundations, Build Tools, and Automation β€” A Clear Breakdown
A

I am a Full-stack dev turning ideas into sleek, functional experiences πŸš€. I am passionate about AI, intuitive UI/UX, and crafting user-friendly platforms . I am always curious – from building websites to diving into machine learning and under the hood workings ✨. Next.js, Node.js, MongoDB, and Tailwind are my daily tools. I am here to share dev experiments, lessons learned, and the occasional late-night code breakthroughs. Always evolving, always building.

This article connects the web layer (Servlets, MVC, Spring), build automation (Maven, Gradle), and testing patterns (Selenium POM).

How Java Handles Web Requests

Java web development stands on a simple idea:
Receive an HTTP request β†’ Process it β†’ Return a response.

Everything else builds on top of this.

1. Servlets

A Servlet is the lowest-level Java class that accepts HTTP requests.

Flow:
Browser β†’ HTTP request β†’ Servlet β†’ Response

Servlet container (like Apache Tomcat) handles:

  • Creating Servlet instances

  • Calling init(), service(), destroy() lifecycle

  • Managing threads for each request

It’s powerful but comes with heavy boilerplate.


2. Java Server Pages (JSP)

JSP was introduced to reduce boilerplate by embedding Java directly inside HTML.
Conceptually similar to EJS in Node.js.

Good for:

  • Small apps

  • UI generation
    Bad for:

  • Large applications

  • Mixing logic + UI

  • Maintainability


3. Spring MVC

Spring MVC brought structure.

  • @Controller handles requests

  • @RequestMapping maps URLs

  • Uses DispatcherServlet (front controller)

  • Clean separation: Controller β†’ Service β†’ Repository β†’ View

Much more maintainable than Servlets or JSP.


4. Spring Boot

Spring Boot sits on top of Spring MVC and solves the biggest pain: configuration.

  • Embedded Tomcat (no manual server setup)

  • Auto-configured MVC

  • Auto-configured Servlets

  • Zero XML

  • Faster development, fewer moving parts


5. Spring Security

Provides authentication and authorization.
Supports:

  • JWT

  • OAuth2

  • Session authentication

  • Custom filters

Designed to integrate smoothly with MVC and microservices.


6. Spring Cloud Gateway

In microservices, you need:

  • Routing

  • Load balancing

  • Central authentication

  • Logging and monitoring

Spring Cloud Gateway provides all these using reactive programming (Project Reactor).


Maven

Maven is a declarative build automation tool that uses XML (POM.xml) to define project configuration.
It focuses on convention over configuration, meaning most project structures and build steps follow standard patterns.

Key Concepts (with explanations)

POM (Project Object Model)

The XML file that defines the project’s metadata, dependencies, plugins, build steps, profiles, and reports.
Maven reads this POM for every command you run.

Maven Build Lifecycle

Maven builds follow three core lifecycles:

  • clean β†’ removes previous build outputs

  • default β†’ compile β†’ test β†’ package β†’ install β†’ deploy

  • site β†’ generates documentation

Each lifecycle contains phases that run in order.

Dependencies

Maven resolves dependencies from:

  • Local Repository β†’ your machine’s .m2

  • Central Repository β†’ default online repo

  • Remote Repositories β†’ company/internal repos

Dependency scopes:

  • compile β†’ needed at compile time

  • runtime β†’ only at runtime

  • test β†’ only during tests

  • provided β†’ provided by container (ex: Tomcat)

Plugins

Every action (compile, package, run tests, generate JAR/WAR) is done by plugins.

Important Maven Commands

  • mvn dependency:tree β†’ see dependency graph

  • mvn clean install β†’ compile, test, package, install

  • mvn -Dmaven.test.skip=true package β†’ skip tests

  • mvn -X β†’ debug mode

  • mvn archetype:generate β†’ create project template

When Maven is Ideal

  • When you want predictable builds

  • When teams prefer XML and static configuration

  • When working with existing enterprise Java apps


Gradle

Gradle is a flexible, programmatic build tool using Groovy/Kotlin DSL.
It focuses on performance, customization, and incremental builds β€” often 2–10Γ— faster.

Key Concepts (with explanations)

Build Scripts (build.gradle)

Instead of XML, Gradle uses Groovy/Kotlin code.
Your build is code, meaning:

  • shorter syntax

  • loops, conditions, functions allowed

  • easier customization

Tasks

Gradle = tasks.
A task is a unit of work (compile, test, copy files, run app).

You can write tasks like:

task hello {
    doLast {
        println "Hello Gradle"
    }
}

Plugins

Plugins add functionality (Java plugin, application plugin, Spring Boot plugin).

Dependency Configurations

  • implementation β†’ used to compile

  • api β†’ exposed to others using your module

  • compileOnly β†’ compile but not runtime

  • runtimeOnly β†’ only needed when running

  • testImplementation β†’ testing

Repositories

Gradle supports:

  • Maven Central

  • Google repo

  • Local repo

  • Custom repo

Gradle Wrapper

Creates:

  • gradlew (Linux/Mac)

  • gradlew.bat (Windows)

This lets you run Gradle without installing it manually.

Useful Commands

  • gradle build

  • gradle clean

  • gradle test

  • gradle tasks

  • gradle dependencies

  • grale build -x test β†’ skip tests

  • gradle build --scan β†’ generate a build performance report

When Gradle is Ideal

  • Microservices, modern cloud apps

  • When build speed matters

  • When customization is required

  • When using Kotlin/Groovy DSL is preferred

Direct Comparison

FeatureMavenGradle
Build LanguageXML (Declarative)Groovy/Kotlin (DSL)
Learning CurveEasyMedium
FlexibilityLowVery High
SpeedModerateMuch Faster (Incremental + caching)
Config TypeStaticCode-like dynamic
Build ScriptsVerboseCompact
Custom TasksHardVery Easy
Enterprise UsageVery commonFast-growing

Extras: Selenium + TestNG + Page Object Model

POM (Page Object Model) is a design pattern for test automation.

Concept

One Java class per page.

Example:

LoginPage.java  
HomePage.java  
ProfilePage.java

Each class contains:

  • WebElements (@FindBy)

  • Actions (login, click, enterText)

Benefits:

  • Reusability

  • Maintainability

  • Cleaner test classes

Build Automation in Java β€” A Clear Guide to Maven & Gradle