Maven is More Popular than Gradle on Enterprise Web Services
Most of the spring boot java web services (eg: Backend API/Microservices based on Spring Boot) for enterprise is done using maven build tools beacuase maven was originally founded on 2004 while gradle is just there after 2009.
The popularity of maven over gradle on enterprise services is also backed up with recent google trends data (as of 9 august 2025)
Moreover, gradle is often used as for mobile development especially for android application.
Maven is used due to the following benefit:
- it manage the project dependencies and package management (all packages are stored on maven central repositories, can be public or private)
- Compile from java source code to binary and run it
- Package the application (either WAR or JAR)
- Publish and manage the artifact on repositories
Requirement to Integrate Maven on the Project
Project skeleton of Maven with Springboot
A specific project skeleton is expected by maven
- src/main/java => location of the java source code files
- src/main/resource => location of the config
- pom.xml on the project root
ensure maven has been installed on the system
via brew
brew install maven
on chocolately
choco install maven
to validate whether maven is installed, execute following command on the terminal
mvn --version
Check Whether maven is installed on the system
it should return the maven version that currently installed to the system
Write the code
Preparing the POM.XML
POM is stands for (project object model) written in XML format. Contains all neccesary configuration of the maven project
Name space and declaration
Maven will expect project tags on beginning and the of the POM.XML files. Its need to be declared using latest POM Schema version possible (Currently 4.0.0 which is been there since 2004)
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
Model version
this need to be aligned with the MXL definition on project tags. It is recommended to use latest version as possible.
<modelVersion>4.0.0</modelVersion>
Project Config
Four item need to be defined here:
- project name space (groupId). Usually start with com.{project_name}
- artifactId : {project_name} (Name of the JAR/WAR file after build completed)
- version : version of the packages/project. Become handy during for release management.
- Pacaking : either JAR or WAR. for springboot its usually JAR
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
Metadata
Describe the project information and name
- name : {project_name}
- description : a short and brief description about the project
<name>demo</name>
<description>Manual Spring Boot App</description>
Maven specific parent POM (Project object model)
Beacuse the project is designed to be sprint boot apps, it need to referenced the Spring boot project POM as the parent. Meaning the project is based on spring boot..
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<relativePath/>
</parent>
replace the 3.3.3 with desired spring boot version. Leave the relative path as is, so it will look up at maven central repositories.
Java Version
Specify the java version. Should be aligned with the specific java version that installed on the server machine.
<properties>
<java.version>17</java.version>
</properties>
maven will build the project based on those specific java version. hence, it is really important to match the java version between development machine and server machine
Depedencies
As the Parent POM defined using spring boot, some package need to be defined. The only mandatory module is Spring boot web start. All of those package (dependency) need to be wrapped in depedencies tags
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
(optional) in case need hot reload
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
(optional) unit testing using JUnit
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
tomcat web server
project will be packaged as executeable jar that compatible with tomcat
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
full version of the pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.milestoneku</groupId>
<artifactId>milestoneku</artifactId>
<version>0.0.1-alpha</version>
<packaging>jar</packaging>
<name>milestoneku</name>
<description>Backend Services for Milestoneku SaaS: A milestone mangement.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<relativePath/>
</parent>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Create main application
align with the groupId defined on the POM.XML
<groupId>com.milestoneku</groupId>
hence the main apps source code would be here
/src/main/java/com/milestoneku/MainApp.java
package com.milestoneku;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApp {
public static void main(String[] args) {
System.out.println("Hello World!");
SpringApplication.run(MainApp.class, args);
}
}
Compile, Build and Run The Maven Project
build to jar
mvn clean package
Apps is started and Hello World is shown on console
run the app
mvn spring-boot:run