Building a Custom Maven Archetype (Scaffolding) for Spring Boot Projects from Scratch

This article explains how to create a reusable Maven archetype for Spring Boot applications, covering the definition and benefits of scaffolding, step‑by‑step template preparation, archetype generation, artifact adjustments, publishing to a repository, and using the scaffold to quickly start new microservice projects.

JD Retail Technology
JD Retail Technology
JD Retail Technology
Building a Custom Maven Archetype (Scaffolding) for Spring Boot Projects from Scratch

Instead of merely providing a project template, this guide teaches you how to build your own scaffolding (Maven archetype) from zero to one, enabling rapid generation of new projects with common configurations.

What is a scaffolding? It is a quick way to create a base project template that includes essential components such as persistence, logging, exception handling, and permission control.

Why use a scaffolding? In micro‑service architectures, many teams need to split monolithic or heavy micro‑service systems into modules (e.g., product, order, user) or domains (e.g., insurance, claims). Manually creating each service repeats boiler‑plate work, risks errors, and wastes resources; a scaffolding automates this process.

Step 1 – Prepare a base Spring Boot template that already integrates common libraries like MyBatis‑Plus, Redis, Logback, Hutool, and Swagger‑UI, or use an existing internal template.

Example Spring Boot template project:

Spring Boot template project
Spring Boot template project

Step 2 – Generate the archetype

2.1 Open the template project in IDEA and verify the Maven path (e.g., D:/Program Files/apache-maven-3.2.5).

D:/Program Files/apache-maven-3.2.5</code>
<code>D:\Program Files\apache-maven-3.2.5\conf\settings.xml</code>
<code>D:\Program Files\apache-maven-3.2.5\repository

2.2 Ensure the template builds successfully.

2.3 Pay attention to the groupId, artifactId, and version in pom.xml (e.g., org.springframework.boot.demo, spring-boot-stage-demo, 0.0.1‑SNAPSHOT).

org.springframework.boot.demo</code>
<code>spring-boot-stage-demo</code>
<code>0.0.1‑SNAPSHOT

2.4 Run the Maven command to create the archetype from the existing project: mvn archetype:create-from-project Alternatively, execute the command from the project directory:

d:</code>
<code>cd D:\spring-stagging</code>
<code>mvn archetype:create-from-project

The generated archetype structure will appear (see Fig. 4).

Archetype project structure
Archetype project structure

If the generated structure is incorrect, adjust the artifactId to match the module prefix.

Adjust artifactId
Adjust artifactId

2.5 Clean IDEA metadata and unnecessary source files:

rm -rf .idea</code>
<code>find . -name ".iml" -type f -print -exec rm -rf {} \;</code>
<code>find . -name "xxxMain" -type f -print -exec rm -rf {} \;

2.6 Publish the archetype by configuring distributionManagement in pom.xml and deploying to your Maven repository (e.g., xxx‑central, xxx‑snapshots).

xxx‑central</code>
<code>libs-releases‑local</code>
<code>http://artifactory.66.com/libs-releases‑local</code>
<code>xxx‑snapshots</code>
<code>libs‑snapshot‑local</code>
<code>http://artifactory.66.com/libs-snapshots‑local

The GAV coordinates to use later are:

org.springframework.boot.demo</code>
<code>spring-boot-stage-demo-archetype</code>
<code>0.0.1‑SNAPSHOT</code>
<code>maven‑archetype
GAV in pom
GAV in pom

Upload the archetype project to a Git repository for future updates.

Step 3 – Use the scaffolding to create new projects

Configure the GAV of the new target project and run Maven archetype generation with the new artifactId.

Example configuration screenshots are provided (Fig. 8‑11).

Configure GAV
Configure GAV
Fill target project GAV
Fill target project GAV

After configuring Maven settings, the new project is generated automatically.

Configure Maven
Configure Maven

Finally, the new project is created based on the updated artifactId (Fig. 11).

Generate new project
Generate new project

Reference

https://maven.apache.org/archetype/maven-archetype-plugin/

Conclusion

Using a custom scaffolding project can reduce the time required to initialize a new engineering project from a day or more to about an hour, greatly improving development efficiency.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mavenSpring BootArchetypeproject scaffolding
JD Retail Technology
Written by

JD Retail Technology

Official platform of JD Retail Technology, delivering insightful R&D news and a deep look into the lives and work of technologists.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.