欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

人工更新项目_SpringBoot打出jar包太大解决方案

程序员文章站 2022-05-04 16:52:47
...

1、问题场景

项目更新,上传整个jar包,太大上,导致上传时间长,更新或升级太慢。

2、解决方案

1)将不经常更新的jar存放至独立文件夹libs下。

2)经常更新的jar打成一个jar。

人工更新项目_SpringBoot打出jar包太大解决方案

3、pom.xml配置

1)最终打成的jar包,含经常更新的jar包

2)文件夹libs踢出经常更新的jar

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/libs</outputDirectory>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <includeScope>runtime</includeScope>
                            <excludeGroupIds>com.mp,com.mp.common.spring,com.mp.common.util</excludeGroupIds>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>com.mp</groupId>
                            <artifactId>mp-dispatch-service-api</artifactId>
                        </include>
                        <include>
                            <groupId>com.mp.common.spring</groupId>
                            <artifactId>common-spring-jpa</artifactId>
                        </include>
                        <include>
                            <groupId>com.mp.common.spring</groupId>
                            <artifactId>common-spring-base</artifactId>
                        </include>
                        <include>
                            <groupId>com.mp.common.util</groupId>
                            <artifactId>common-util</artifactId>
                        </include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                            <goal>build-info</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>