How to Build a Maven Archetype Scaffold for Spring Boot Projects
This guide explains what a scaffolding tool is, why it’s essential for micro‑service development, and provides step‑by‑step instructions for creating, publishing, and using a Maven archetype scaffold with Spring Boot, including Maven configuration, version handling, and repository deployment.
What Is a Scaffold
A scaffold is an infrastructure tool that quickly generates a project's framework code and file structure, providing a standardized way for developers to set up a system with basic functionality and architecture early in the development cycle.
Why Scaffolding Matters
In micro‑service architectures, companies often split monolithic or heavy micro‑service systems into modules (e.g., product, order, user, inventory) or domain‑driven designs (e.g., insurance, claims, payment). Manually creating each micro‑service repeats effort, risks errors, and wastes resources. A scaffold that pre‑generates common layers such as persistence, logging, exception handling, and permission control reduces risk and improves efficiency.
Creating a Scaffold
3.1 Write a Project Template
Start with a base project template that includes common dependencies like MyBatis‑Plus, Redis, Logback, Hutool, and Swagger‑UI. You can build your own or use an existing Spring Boot template.
3.2 Generate the Scaffold
3.2.1 Open the Template in IDEA
Open the base project in IDEA and verify the Maven configuration path, ensuring it remains consistent.
D:/Program Files/apache-maven-3.2.5 D:\Program Files\apache-maven-3.2.5\conf\settings.xml D:\Program Files\apache-maven-3.2.5\repository3.2.2 Pay Attention to Version Numbers
Check the pom.xml for the project's GAV (groupId, artifactId, version) as it will be used when generating the scaffold.
3.2.3 Build the Scaffold
Method 1: In a terminal, run: mvn archetype:create-from-project Method 2: From the project directory, execute:
cd D:\spring-stagging mvn archetype:create-from-projectAfter execution, the scaffold project is created, showing a structure like the following:
If the generated structure has mismatched artifactId and module prefixes, adjust them to be consistent.
3.2.4 Clean Up the Scaffold
Remove IDE files and unnecessary example code:
rm -rf .idea find . -name ".iml" -type f -print -exec rm -rf {} \; find . -name "xxxMain" -type f -print -exec rm -rf {} \;Place the resulting scaffold (containing src and pom.xml) in a directory such as D:\spring-stagging-archetype.
3.2.5 Publish the Scaffold
Configure Maven’s distributionManagement and deploy the scaffold to the artifact repository. Failure to do so may result in errors like “Could not find artifact org.springframework.boot.demo:spring-boot-stage-demo-archetype:pom:0.0.1‑SNAPSHOT”.
xxx-central libs-releases-local http://artifactory.66.com/libs-releases-local xxx-snapshots libs-snapshot-local http://artifactory.66.com/libs-snapshots-localThe GAV coordinates for the scaffold are:
org.springframework.boot.demo spring-boot-stage-demo-archetype 0.0.1‑SNAPSHOT maven-archetypeUpload the scaffold project to a Git repository for future updates and maintenance.
Using the Scaffold to Create New Projects
4.1 Configure the Scaffold’s GAV
4.2 Fill in the Target Project’s GAV
4.3 Configure Maven
4.4 Generate a New Project Using the New ArtifactId
Reference
[1] https://maven.apache.org/archetype/maven-archetype-plugin/
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
JD Cloud Developers
JD Cloud Developers (Developer of JD Technology) is a JD Technology Group platform offering technical sharing and communication for AI, cloud computing, IoT and related developers. It publishes JD product technical information, industry content, and tech event news. Embrace technology and partner with developers to envision the future.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
