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

效果如下所示

相关推荐
一只叫煤球的猫5 小时前
写代码很6,面试秒变菜鸟?不卖课,面试官视角走心探讨
前端·后端·面试
bobz9655 小时前
tcp/ip 中的多路复用
后端
bobz9656 小时前
tls ingress 简单记录
后端
皮皮林5517 小时前
IDEA 源码阅读利器,你居然还不会?
java·intellij idea
你的人类朋友7 小时前
什么是OpenSSL
后端·安全·程序员
bobz9657 小时前
mcp 直接操作浏览器
后端
前端小张同学9 小时前
服务器部署 gitlab 占用空间太大怎么办,优化思路。
后端
databook10 小时前
Manim实现闪光轨迹特效
后端·python·动效
武子康10 小时前
大数据-98 Spark 从 DStream 到 Structured Streaming:Spark 实时计算的演进
大数据·后端·spark
该用户已不存在10 小时前
6个值得收藏的.NET ORM 框架
前端·后端·.net