今天某个工程执行mvn clean install
时,没有成功构建fatjar,只有一个非fatjar。
之前是OK的
于是git查看了修改记录。从修改记录中发现,工程pom.xml从继承spring-boot-starter-parent
,变为了依赖spring-boot-dependencies
。版本是没有变化的。
于是查了资料才知道:
继承自spring-boot-starter-parent
的SpringBoot工程,只需如下代码即可构建fatjar:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
而其他方式的SpringBoot工程,则需要,显式声明构建目标:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- spring-boot-maven-plugin 构建fatjar必须有如下部分,如果项目直接或间接继承spring-boot-starter-parent, 则可以不用写,因为parent中为我们写好了.-->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>