Maven packs and puts third-party jars in the external lib directory, leaving only the jars you specify

I am here about the problem encountered when springBoot is packaged; every time I package and upload the test, I have to upload the third-party unchanging jar, and the packaged jar packages also account for the largest proportion, regardless of the occupied bandwidth or duration. optimized

1. Maven hit war package:

Add a plug-in: the packagingIncludes label is the jar that is reserved when packaging is specified

            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <archiveClasses>false</archiveClasses>
                    <packagingIncludes>
                        WEB-INF/lib/api-1.0.0.jar,
                        WEB-INF/lib/commom-1.0.0.jar,
                        WEB-INF/lib/util-1.0.0.jar,
                        WEB-INF/classes/**
                    </packagingIncludes>
                </configuration>
            </plugin>

2. Maven hit jar package:

At that time, I searched the Internet for a long time; it was nothing more than copying the third-party jar package when packaging and leaving only the jar package you want.

           <!-- spring-boot-maven 打包插件 -->
            <plugin>
                <!--打包时去除第三方依赖-->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>non-exists</groupId>
                            <artifactId>non-exists</artifactId>
                        </include>

                      <!--  <include>-->
                      <!--       <groupId>自己jar包的groupId</groupId>-->
                            <artifactId>自己jar包的artifactId</artifactId>-->
                      <!-- </include>-->

                    </includes>
                </configuration>
            </plugin>
            <!--拷贝第三方依赖文件到指定目录-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <!--target/lib是依赖jar包的输出目录,根据自己喜好配置-->
                            <outputDirectory>target/lib</outputDirectory>
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <includeScope>com</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

 

Guess you like

Origin blog.csdn.net/qq_38130094/article/details/108326219