通过mvn archetype 创建一个spring boot start 工程

mvn archetype

遇到的问题

对于想自定义一个spring-boot-start的同学,比如 Springboot自定义Starter启动器

整个过程很繁琐。

  • 定义属性开关
  • 增加 spring boot test start插件
  • 定义自动装载 spring.factories or org.springframework.boot.autoconfigure.AutoConfiguration.imports
  • ...
  • 也不多,操作一波半小时到一小时过去了...,即使熟悉的也是各种拷贝过来

想通过mvn archetype 可以提供脚手架创建一个基础模板出来,简单的实现了一个,也不是很复杂。

创建一个spring-boot-start的mvn 脚手架

Generate project in batch mode

archetype mvn info

xml 复制代码
<dependency>
    <groupId>com.github.WangJi92</groupId>
    <artifactId>kunlun-boot-start-archetype</artifactId>
    <version>0.0.4</version>
</dependency>

create command

  • autoConfigName 自动装配的类名称
  • propertiesPrefix 自动装配属性的前缀
  • author 备注信息的作者
  • date 备注信息的时间
  • springBootVersion spring 的版本

  • "-DartifactId=Lassen" 工程的名称 && mvn 坐标
  • "-Dpackage=io.github.example" 包名称
  • "-DgroupId=io.github.example" mvn 坐标分组

一键生成命令行 (mac) \ 换行符合

bash 复制代码
mvn archetype:generate -B "-DarchetypeGroupId=com.github.WangJi92" \
                          "-DarchetypeArtifactId=kunlun-boot-start-archetype" \
                          "-DarchetypeVersion=0.0.4"  \
                          "-DgroupId=io.github.example" \
                          "-Dpackage=io.github.example" \
                          "-DartifactId=name-artifactId" \
                          "-DspringBootVersion=2.7.18" \
                          "-DautoConfigName=BootStartExample" \
                          "-DpropertiesPrefix=example.core" \
                          "-Dauthor=author" \
                          "-Dversion=1.0-SNAPSHOT" \
                          "-Ddate=2024-4-13 12:19"

一键生成命令行 (powershell) ` 换行符合

在 PowerShell 中,换行使用的是反引号 (`)。但是在使用时,反引号后面不能有空格或其他字符,要求紧跟着换行

bash 复制代码
mvn archetype:generate -B "-DarchetypeGroupId=com.github.WangJi92" `
                          "-DarchetypeArtifactId=kunlun-boot-start-archetype" `
                          "-DarchetypeVersion=0.0.4"  `
                          "-DgroupId=io.github.example" `
                          "-Dpackage=io.github.example" `
                          "-DartifactId=name-artifactId" `
                          "-DspringBootVersion=2.7.18" `
                          "-DautoConfigName=BootStartExample" `
                          "-DpropertiesPrefix=example.core" `
                          "-Dauthor=author" `
                          "-Dversion=1.0-SNAPSHOT" `
                          "-Ddate=2024-4-13 12:19"

idea add mvn archetype

总结

下面就可以愉快的创建一个spring boot start 工程了

效果如下所示

相关推荐
leobertlan3 小时前
2025年终总结
前端·后端·程序员
面向Google编程3 小时前
从零学习Kafka:数据存储
后端·kafka
易安说AI4 小时前
Claude Opus 4.6 凌晨发布,我体验了一整晚,说说真实感受。
后端
易安说AI4 小时前
Ralph Loop 让Claude无止尽干活的牛马...
前端·后端
易安说AI4 小时前
用 Claude Code 远程分析生产日志,追踪 Claude Max 账户被封原因
后端
JH30734 小时前
SpringBoot 优雅处理金额格式化:拦截器+自定义注解方案
java·spring boot·spring
CHHYQMGDCDZu5 小时前
光伏系统参数
maven
颜酱5 小时前
图结构完全解析:从基础概念到遍历实现
javascript·后端·算法
Coder_Boy_6 小时前
技术让开发更轻松的底层矛盾
java·大数据·数据库·人工智能·深度学习
invicinble6 小时前
对tomcat的提供的功能与底层拓扑结构与实现机制的理解
java·tomcat