bbb
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.huawei.kirin</groupId>
<artifactId>kits-backend</artifactId>
<version>0.1.0</version>
<properties>
<!-- ===== 语言版本 ===== -->
<java.version>21</java.version>
<kotlin.version>2.3.0</kotlin.version>
<!-- ===== 依赖版本 ===== -->
<colleen.version>0.2.1</colleen.version>
<cleary.version>0.1.1</cleary.version>
<slf4j.version>2.0.9</slf4j.version>
<logback.version>1.5.27</logback.version>
<junit.version>5.11.4</junit.version>
<dotenv.verion>3.2.0</dotenv.verion>
<jooq.version>3.20.11</jooq.version>
<hikari.version>7.0.2</hikari.version>
<postgres.version>42.7.10</postgres.version>
<mongodb.version>5.6.4</mongodb.version>
<flyway.version>12.0.2</flyway.version>
<!-- ===== 构建配置 ===== -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>${java.version}</kotlin.compiler.jvmTarget>
<!-- ===== 插件版本 ===== -->
<maven-compiler-plugin.version>3.15.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.5.4</maven-surefire-plugin.version>
<maven-shade-plugin.version>3.5.1</maven-shade-plugin.version>
<exec-maven-plugin.version>3.6.3</exec-maven-plugin.version>
<properties-maven-plugin.version>1.2.1</properties-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>io.github.cymoo</groupId>
<artifactId>colleen</artifactId>
<version>${colleen.version}</version>
</dependency>
<dependency>
<groupId>io.github.cymoo</groupId>
<artifactId>cleary</artifactId>
<version>${cleary.version}</version>
</dependency>
<dependency>
<groupId>io.github.cdimascio</groupId>
<artifactId>dotenv-java</artifactId>
<version>${dotenv.verion}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>${mongodb.version}</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${hikari.version}</version>
</dependency>
<!-- Flyway 核心库,提供运行时数据库迁移能力 -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flyway.version}</version>
</dependency>
<!-- Flyway PostgreSQL 支持,Flyway 10+ 数据库支持从核心库拆分为独立模块 -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<version>${flyway.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<!-- process-sources 确保在 generate-sources 生成的 JOOQ 代码之后编译 -->
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>${kotlin.compiler.jvmTarget}</jvmTarget>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
</plugin>
<!-- 打包为包含所有依赖的可执行 fat jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>MainKt</mainClass>
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<!--
在 initialize 阶段加载 .env 文件为 Maven properties,供后续插件使用。
加载优先级(后加载的覆盖先加载的):
.env → 公共默认值,提交到 git
.env.${COLLEEN_ENV} → 环境特定值,如 .env.dev / .env.ci
.env.local → 本地个人覆盖,加入 .gitignore,最高优先级
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>${properties-maven-plugin.version}</version>
<executions>
<execution>
<id>read-env</id>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}/.env</file>
<file>${project.basedir}/.env.${COLLEEN_ENV}</file>
<file>${project.basedir}/.env.local</file>
</files>
<!-- 文件不存在时静默跳过,避免 CI 环境缺少某些文件时报错 -->
<quiet>true</quiet>
</configuration>
</execution>
</executions>
</plugin>
<!--
在 generate-sources 阶段迁移【本地/CI 库】,目的是让 JOOQ 有完整的表结构可以生成代码。
注意:此处连接的是开发库或 CI 临时库,与生产库无关。
生产库的迁移由运行时 FlywayConfig.migrate() 负责(应用启动时执行)。
执行顺序(同一 phase 内按声明顺序):
1. flyway:migrate → 迁移本地/CI库
2. jooq:generate → 从迁移后的库生成代码
-->
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>${flyway.version}</version>
<executions>
<execution>
<id>flyway-migrate-for-codegen</id>
<phase>generate-sources</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
</executions>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<url>jdbc:postgresql://${KITS_PG_HOST}:${KITS_PG_PORT}/${KITS_PG_DB}</url>
<!--suppress UnresolvedMavenProperty -->
<user>${KITS_PG_USER}</user>
<!--suppress UnresolvedMavenProperty -->
<password>${KITS_PG_PASSWORD}</password>
<!--
以下参数必须与运行时 FlywayConfig 保持一致,
否则两者对迁移历史的判断会产生冲突。
-->
<!-- 对已有数据建立基线,避免将存量数据误判为未迁移 -->
<baselineOnMigrate>true</baselineOnMigrate>
<!-- 注意:Flyway 默认值为 1,此处显式设为 0 需与运行时保持一致 -->
<baselineVersion>0</baselineVersion>
<!--
本地/CI 允许 clean(方便重置开发库),运行时 FlywayConfig 中 cleanDisabled=true 禁止清库。
两者不一致是有意为之,clean 操作只应发生在非生产环境。
-->
<cleanDisabled>false</cleanDisabled>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- 从数据库表结构生成 JOOQ 类型安全的 DSL 代码 -->
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<executions>
<execution>
<id>generate-jooq</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbc>
<driver>org.postgresql.Driver</driver>
<!--suppress UnresolvedMavenProperty -->
<url>jdbc:postgresql://${KITS_PG_HOST}:${KITS_PG_PORT}/${KITS_PG_DB}</url>
<!--suppress UnresolvedMavenProperty -->
<username>${KITS_PG_USER}</username>
<!--suppress UnresolvedMavenProperty -->
<password>${KITS_PG_PASSWORD}</password>
</jdbc>
<generator>
<database>
<name>org.jooq.meta.postgres.PostgresDatabase</name>
<inputSchema>public</inputSchema>
<includes>.*</includes>
<!-- 排除 Flyway 迁移历史表,无需为其生成 JOOQ 代码 -->
<excludes>flyway_schema_history</excludes>
</database>
<target>
<!-- 生成到 target 目录,不纳入版本控制 -->
<packageName>kits.jooq.generated</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
<generate>
<pojos>true</pojos>
<daos>true</daos>
</generate>
</generator>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
<!--
dev profile:本地开发默认激活。
COLLEEN_ENV=dev,对应加载 .env.dev 文件。
-->
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<COLLEEN_ENV>dev</COLLEEN_ENV>
</properties>
</profile>
<!--
from-env profile:检测到系统环境变量 COLLEEN_ENV 时自动激活(优先级高于 dev)。
用于 CI/CD 环境,通过环境变量控制加载哪个 .env 文件,无需手动指定 -P 参数。
例如:export COLLEEN_ENV=ci → 加载 .env.ci
-->
<profile>
<id>from-env</id>
<activation>
<property>
<name>env.COLLEEN_ENV</name>
</property>
</activation>
<properties>
<COLLEEN_ENV>${env.COLLEEN_ENV}</COLLEEN_ENV>
</properties>
</profile>
</profiles>
</project>