SpringBoot打包瘦身
获取lib
先用正常方式打包 解压原始jar包 获取boot-Inf目录中的lib目录 拷贝到服务器上
打包跳过lib中的Jar包
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>cn.duckflew.NotepadApplication</mainClass>
<layout>ZIP</layout>
<includes>
<include>
<groupId>nothing</groupId>
<artifactId>nothing</artifactId>
</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
选择性打包
不是lib包中所有的jar都是不频繁变动的,假设我们依赖了项目中的其他模块,那么我们需要把这些模块也全部打包进去,不适合作为lib放到服务器上面异步加载
<configuration>
<mainClass>com.tkelevator.RmsAdminApplication</mainClass>
<layout>ZIP</layout>
<includes>
<include>
<groupId>com.tkelevator</groupId>
<artifactId>rms-service</artifactId>
</include>
<include>
<groupId>com.tkelevator</groupId>
<artifactId>rms-mapper</artifactId>
</include>
<include>
<groupId>com.tkelevator</groupId>
<artifactId>rms-common</artifactId>
</include>
<include>
<groupId>com.tkelevator</groupId>
<artifactId>rms-model</artifactId>
</include>
</includes>
</configuration>
瘦身之后的效果
可以看到,Jenkins部署的时间从之前的5分钟缩短到了1分钟不到