该目标功能:将依赖的 jar 包下载到指定的文件夹中。并不一起打包到最终包中。
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>earth</artifactId> <groupId>ymqx.com</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>portal</artifactId> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>${project.groupId}</groupId> <artifactId>service</artifactId> <version>${project.version}</version> </dependency> </dependencies> <build> <plugins> <!-- 使用spring-boot-maven-plugin打包独立可执行程序 --> <!--<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.4.2.RELEASE</version> <configuration> <finalName>earth</finalName> <classifier>1.0-SNAPSHOT</classifier> <outputDirectory>../target</outputDirectory> </configuration> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin>--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.0.1</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
执行打包后:
portal模块生成目录target下增加一个文件夹lib,lib包含所有依赖:
一共33个依赖包,和repackage生成earth-1.0-SNAPSHOT.jar\BOOT-INF\lib一样。
注:portal-1.0-SNAPSHOT.jar 没有依赖包:
参考:https://blog.csdn.net/weixin_40017062/article/details/122711348