通过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


<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) \ 换行符合

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 中,换行使用的是反引号 (`)。但是在使用时,反引号后面不能有空格或其他字符,要求紧跟着换行

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
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值