build: 重构打包配置以同时支持胖包和瘦包模式

This commit is contained in:
liquor
2025-11-05 03:49:14 +00:00
committed by Charles7c
parent 68a1227945
commit 6be14b59b1

View File

@@ -81,82 +81,134 @@
<!-- 设置构建的 jar 包名 -->
<finalName>${project.parent.name}</finalName>
<plugins>
<!-- Maven 打包插件 -->
<!-- Spring Boot 可执行 JAR 打包插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 排除配置文件 -->
<excludes>
<exclude>${config-path}</exclude>
<exclude>db/</exclude>
<exclude>templates/</exclude>
<exclude>logback-spring.xml</exclude>
</excludes>
<archive>
<manifest>
<mainClass>${main-class}</mainClass>
<!-- 为 MANIFEST.MF 中的 Class-Path 加入依赖 jar 目录前缀 -->
<classpathPrefix>../${lib-path}</classpathPrefix>
<addClasspath>true</addClasspath>
<!-- jar 包不包含唯一版本标识 -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
<manifestEntries>
<!--为 MANIFEST.MF 中的 Class-Path 加入配置文件目录前缀 -->
<Class-Path>../${config-path}</Class-Path>
</manifestEntries>
</archive>
<outputDirectory>${project.build.directory}/app/${bin-path}</outputDirectory>
<includeSystemScope>true</includeSystemScope>
<skip>${skip.boot.repackage}</skip>
</configuration>
</plugin>
<!-- 拷贝依赖 jar -->
<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>
<goal>repackage</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/app/${lib-path}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- 拷贝配置文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources/${config-path}</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>db/</include>
<include>templates/</include>
<include>logback-spring.xml</include>
</includes>
</resource>
</resources>
<outputDirectory>${project.build.directory}/app/${config-path}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<!-- 默认 Spring Boot 胖包 模式 -->
<profile>
<id>fat_jar</id>
<properties>
<skip.boot.repackage>false</skip.boot.repackage>
</properties>
</profile>
<!-- 瘦包 模式(可执行 JAR + lib + config -->
<profile>
<id>slim_jar</id>
<!--默认-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<skip.boot.repackage>true</skip.boot.repackage>
<!-- 路径变量 -->
<lib-path>lib/</lib-path>
<config-path>config/</config-path>
<bin-path>bin/</bin-path>
<!-- 启动类 -->
<main-class>top.continew.admin.ContiNewAdminApplication</main-class>
</properties>
<build>
<plugins>
<!-- 分离打包 JAR不包含依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- 排除配置文件 -->
<excludes>
<exclude>${config-path}</exclude>
<exclude>db/</exclude>
<exclude>templates/</exclude>
<exclude>logback-spring.xml</exclude>
</excludes>
<archive>
<manifest>
<mainClass>${main-class}</mainClass>
<!-- 为 MANIFEST.MF 中的 Class-Path 加入依赖 jar 目录前缀 -->
<classpathPrefix>../${lib-path}</classpathPrefix>
<addClasspath>true</addClasspath>
<!-- jar 包不包含唯一版本标识 -->
<useUniqueVersions>false</useUniqueVersions>
</manifest>
<manifestEntries>
<!--为 MANIFEST.MF 中的 Class-Path 加入配置文件目录前缀 -->
<Class-Path>../${config-path}</Class-Path>
</manifestEntries>
</archive>
<outputDirectory>${project.build.directory}/app/${bin-path}</outputDirectory>
</configuration>
</plugin>
<!-- 拷贝依赖 jar -->
<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>
<outputDirectory>${project.build.directory}/app/${lib-path}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- 拷贝配置文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources/${config-path}</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>db/</include>
<include>templates/</include>
<include>logback-spring.xml</include>
</includes>
</resource>
</resources>
<outputDirectory>${project.build.directory}/app/${config-path}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>