通过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 工程了

效果如下所示

相关推荐
倔强的石头_3 小时前
WorkBuddy 上手实战:打造一个可用的本地 AI 工作台
后端
苍何8 小时前
Coding 真有质的飞跃?实测下豆包seed 2.1 pro
后端
苍何8 小时前
试了下腾讯 Marvis,回不去了...
后端
caibixyy8 小时前
springboot+langchain4j 实战 Day14——工具嵌入多 Agent(Tool-Equipped Multi-Agent)
后端
caibixyy8 小时前
springboot+langchain4j 实战 Day13 多 Agent 协作(Router + 子 Agent 分流)
后端
飘尘8 小时前
前端转全栈(Java 后端)必须要知道的:开发中的锁机制与分布式并发控制
前端·后端·全栈
苍何8 小时前
清华团队做了个具身智能大脑,有点东西!
后端
fliter8 小时前
强类型的诅咒,还是 Rust 类型系统的生存指南
后端
用户8356290780519 小时前
Python 操作 PDF 附件:添加、查看与管理指南
后端·python