ci: 👷 调整项目打包结构,分离依赖、配置文件

1.调整 Spring Boot 配置文件到 config 目录
2.移除 Maven Profiles 配置
3.调整项目打包结构,分离依赖、配置文件。如无依赖调整,部署时仅需拷贝程序包,且更方便进行配置修改
4.调整后的项目打包结构,更贴合部署安装程序结构,例如:Tomcat 安装包、Maven 安装包
5.建议在 bin 目录上一级执行程序,以使日志文件能正确生成在 logs 目录下,参考 Dockerfile
This commit is contained in:
2023-09-07 00:41:18 +08:00
parent 5c9e6639db
commit e679abfccc
9 changed files with 106 additions and 83 deletions

View File

@@ -31,6 +31,18 @@ limitations under the License.
<name>${project.artifactId}</name>
<description>API 模块(存放 Controller 层代码,打包部署的模块)</description>
<properties>
<!-- ### 打包配置相关 ### -->
<!-- 启动类 -->
<main-class>top.charles7c.cnadmin.ContiNewAdminApplication</main-class>
<!-- 程序 jar 输出目录 -->
<bin-path>bin</bin-path>
<!-- 配置文件输出目录 -->
<config-path>config</config-path>
<!-- 依赖 jar 输出目录 -->
<lib-path>lib</lib-path>
</properties>
<dependencies>
<!-- Liquibase用于管理数据库版本跟踪、管理和应用数据库变化 -->
<dependency>
@@ -66,34 +78,77 @@ limitations under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
<!-- 根据启用环境执行对应 @Tag 的测试方法 -->
<groups>${profiles.active}</groups>
<!-- 排除标签 -->
<excludedGroups>exclude</excludedGroups>
<!-- 跳过单元测试 -->
<skip>true</skip>
</configuration>
</plugin>
<!-- Spring Boot 打包插件(将 Spring Boot Maven 应用打包为可执行的 jar 包) -->
<!-- Maven 打包插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<!-- 排除配置文件 -->
<excludes>
<exclude>${config-path}/</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>repackage</goal>
<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</directory>
<includes>
<include>${config-path}/</include>
</includes>
</resource>
</resources>
<outputDirectory>${project.build.directory}/app</outputDirectory>
</configuration>
</execution>
</executions>
<configuration>
<!-- 在新的 JVM 进程中运行打包任务(另注:在使用 devtools 时,如果没有该项配置,热部署可能会失效) -->
<fork>true</fork>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

View File

@@ -138,6 +138,13 @@ rsa:
# 私钥
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
--- ### 日志配置
logging:
level:
top.charles7c: DEBUG
file:
path: ./logs
--- ### 接口文档配置
springdoc:
swagger-ui:

View File

@@ -131,6 +131,13 @@ rsa:
# 私钥
privateKey: MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAznV2Bi0zIX61NC3zSx8U6lJXbtru325pRV4Wt0aJXGxy6LMTsfxIye1ip+f2WnxrkYfk/X8YZ6FWNQPaAX/iRwIDAQABAkEAk/VcAusrpIqA5Ac2P5Tj0VX3cOuXmyouaVcXonr7f+6y2YTjLQuAnkcfKKocQI/juIRQBFQIqqW/m1nmz1wGeQIhAO8XaA/KxzOIgU0l/4lm0A2Wne6RokJ9HLs1YpOzIUmVAiEA3Q9DQrpAlIuiT1yWAGSxA9RxcjUM/1kdVLTkv0avXWsCIE0X8woEjK7lOSwzMG6RpEx9YHdopjViOj1zPVH61KTxAiBmv/dlhqkJ4rV46fIXELZur0pj6WC3N7a4brR8a+CLLQIhAMQyerWl2cPNVtE/8tkziHKbwW3ZUiBXU24wFxedT9iV
--- ### 日志配置
logging:
level:
top.charles7c: INFO
file:
path: ./logs
--- ### 接口文档配置
springdoc:
swagger-ui:

View File

@@ -26,10 +26,6 @@ project:
--- ### 日志配置(重叠部分,优先级高于 logback-spring.xml 中的配置)
logging:
level:
top.charles7c: @logging.level@
file:
path: @logging.file.path@
config: classpath:logback-spring.xml
## 系统日志配置
system:
@@ -186,8 +182,7 @@ spring:
## 环境配置
profiles:
# 启用的环境
# 配合 Maven Profile 选择不同配置文件进行启动,在 IntelliJ IDEA 右侧 Maven 工具窗口可以快速切换环境
active: @profiles.active@
active: dev
main:
# 允许定义重名的 bean 对象覆盖原有的 bean
allow-bean-definition-overriding: true