介绍
The Spring Boot Maven Plugin Plugin provides Spring Boot support in Maven, allowing you to package executable jar or war archives and run an application “in-place”.
spring-boot-starter-parent的<pluginManagement/>下定义了spring-boot-maven-plugin
1 | |
包含有多个goal,比如:repackage、run、start、stop和buid-info
goals
repackage
repackage,顾名思义,再打包,默认再打包成一个可执行的archive(包含依赖(compile,runtime,provide,非test,非system)),原打包的archive被重命名(后面追加.original),绑定到maven的package阶段
| 参数 | 描述 | 默认值 |
|---|---|---|
| attach | true:安装部署repackage的包,false:安装部署原始包(不带.original后缀) | true |
| classifier | repackage包追加的后缀,原始包则不追加.original,此时两个包都会被安装部署 | 空 |
| excludes | ||
| excludeGroupIds | ||
| excludeArtifactIds | ||
| skip | 跳过执行 | false |
| excludeDevtools | exclude devtools | true |
| layout | The type of archive (which corresponds to how the dependencies arelaid out inside it). Possible values are JAR, WAR, ZIP, DIR, NONE.Defaults to a guess based on the archive type. |
JAR: regular executable JAR layout (BOOT-INF/lib/).WAR: executable WAR layout.provideddependencies are placed inWEB-INF/lib-providedto avoid any clash when thewaris deployed in a servlet container (WEB-INF/lib/andWEB-INF/lib-provided/).ZIP(alias toDIR): similar to theJARlayout usingPropertiesLauncher(BOOT-INF/lib/and environment variableLOADER_PATHand system propertyloader.path).MODULE: Bundle dependencies (excluding those withprovidedscope) and project resources. Does not bundle a bootstrap loader.NONE: Bundle all dependencies and project resources. Does not bundle a bootstrap loader.
样例(MANIFEST.inf)
1 | |
run
run:运行spring boot应用。
1 | |
| 参数 | 描述 | 默认值 |
|---|---|---|
| fork | User property: fork,是否另起进程,当agent, jvmArguments和workingDirectory设置或devtools存在时自动为true | false |
| jvmArguments | User property: run.jvmArguments | |
start
| 参数 | 描述 | 默认值 |
|---|---|---|
stop
build-info
spring-boot:build-info generates build information that can be used by the Actuator.
参数
layout
默认可执行的archive会自包含依赖,导致archive体积都会很大,某些场景下不太适合,这时可以将依赖放到外部,其他基本不变。layout设定为ZIP,同时将依赖exclude,这样repackage的archive也是可执行的,只是不再自包含依赖。
1 | |
执行:
1 | |
这种方式最大的问题是排查依赖必须精确匹配,不支持模糊匹配,不够灵活,操作起来较为麻烦