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

效果如下所示

相关推荐
苍煜11 分钟前
慢SQL优化实战教学
java·数据库·sql
AI进化营-智能译站14 分钟前
ROS2 C++开发系列16-智能指针管理传感器句柄|告别ROS2节点内存泄漏与野指针
java·c++·算法·ai
TeDi TIVE1 小时前
springboot和springframework版本依赖关系
java·spring boot·后端
雨辰AI1 小时前
SpringBoot3 + 人大金仓 V9 微服务监控实战|Prometheus+Grafana+SkyWalking 全链路监控
数据库·后端·微服务·grafana·prometheus·skywalking
二哈赛车手1 小时前
新人笔记---ES和kibana启动问题以及一些常用的linux的错误排查方法,以及ES,数据库泄密解决方案[超详细]
java·linux·数据库·spring boot·笔记·elasticsearch
myrh pdmd1 小时前
maven导入spring框架
数据库·spring·maven
嵌入式×边缘AI:打怪升级日志1 小时前
嵌入式Linux开发核心自测题(全系列精华浓缩)
java·linux·运维
Nicander1 小时前
理解 mybatis 源码:vibe-coding一个mini-mybatis
后端·mybatis
FQNmxDG4S1 小时前
JVM内存模型详解:堆、栈、方法区与垃圾回收
java·jvm·算法
jason.zeng@15022072 小时前
Androidr入门环境搭建
java·kotlin