<?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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.5.7</version>
        <relativePath />
    </parent>

    <groupId>cn.meowrain.aioj</groupId>
    <artifactId>ai-oj</artifactId>
    <version>${revision}</version>
    <packaging>pom</packaging>
    <name>ai-oj-microservices</name>
    <description>一款集成了AI功能的OJ判题系统</description>

    <modules>
        <module>aioj-backend-common</module>
        <module>aioj-backend-gateway</module>
        <module>aioj-backend-judge-service</module>
        <module>aioj-backend-user-service</module>
        <module>aioj-backend-question-service</module>
        <module>aioj-backend-ai-service</module>
        <module>aioj-backend-auth</module>
        <module>aioj-backend-upms</module>
        <module>aioj-backend-file-service</module>
    </modules>

    <properties>
        <!-- ==================== 项目基础配置 ==================== -->
        <revision>1.0.0</revision>
        <java.version>17</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        
        <!-- ==================== Spring生态版本 ==================== -->
        <spring-boot.version>3.5.7</spring-boot.version>
        <spring-cloud.version>2025.0.0</spring-cloud.version>
        <spring-cloud-alibaba.version>2025.0.0.0</spring-cloud-alibaba.version>
        
        <!-- ==================== 构建插件版本 ==================== -->
        <spring.checkstyle.plugin>0.0.47</spring.checkstyle.plugin>
        <git.commit.plugin>9.0.2</git.commit.plugin>
        <maven.compiler.plugin.version>3.14.1</maven.compiler.plugin.version>
        <jib.plugin.version>3.4.5</jib.plugin.version>
        <flatten.plugin.version>1.6.0</flatten.plugin.version>
        
        <!-- ==================== Docker配置 ==================== -->
        <docker.spring.active>dev</docker.spring.active>
    </properties>

    <!-- 全局依赖：所有子模块都会继承 -->
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <!-- AIOJ 内部模块BOM (优先级最高，放在最前面) -->
            <dependency>
                <groupId>cn.meowrain.aioj</groupId>
                <artifactId>aioj-backend-common-bom</artifactId>
                <version>${revision}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            
            <!-- Spring Boot 依赖管理 -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            
            <!-- Spring Cloud 依赖管理 -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            
            <!-- Spring Cloud Alibaba 依赖管理 -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${spring-cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        
        <plugins>
            <!-- Java 编译插件 -->
            <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>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            
            <!-- Spring Boot Maven 插件 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
            </plugin>
            
            <!-- Flatten 插件：处理 ${revision} 变量 -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>${flatten.plugin.version}</version>
                <configuration>
                    <updatePomFile>true</updatePomFile>
                    <flattenMode>resolveCiFriendliesOnly</flattenMode>
                </configuration>
                <executions>
                    <execution>
                        <id>flatten</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>flatten.clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <!-- 代码格式插件 -->
            <plugin>
                <groupId>io.spring.javaformat</groupId>
                <artifactId>spring-javaformat-maven-plugin</artifactId>
                <version>${spring.checkstyle.plugin}</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <inherited>true</inherited>
                    </execution>
                </executions>
            </plugin>

            <!-- Git Commit 信息插件 -->
            <plugin>
                <groupId>io.github.git-commit-id</groupId>
                <artifactId>git-commit-id-maven-plugin</artifactId>
                <version>${git.commit.plugin}</version>
                <executions>
                    <execution>
                        <id>get-the-git-infos</id>
                        <phase>initialize</phase>
                    </execution>
                </executions>
                <configuration>
                    <failOnNoGitDirectory>false</failOnNoGitDirectory>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
                    <includeOnlyProperties>
                        <includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
                        <includeOnlyProperty>^git.commit.(id|message|time).*$</includeOnlyProperty>
                    </includeOnlyProperties>
                </configuration>
            </plugin>
        </plugins>
        
        <pluginManagement>
            <plugins>
                <!-- JIB Docker 镜像构建插件 -->
                <plugin>
                    <groupId>com.google.cloud.tools</groupId>
                    <artifactId>jib-maven-plugin</artifactId>
                    <version>${jib.plugin.version}</version>
                    <configuration>
                        <allowInsecureRegistries>true</allowInsecureRegistries>
                        <from>
                            <!--使用openjdk官方镜像，tag是8-jdk-stretch，表示镜像的操作系统是debian9,装好了jdk8-->
                            <image>
                                registry.cn-shanghai.aliyuncs.com/all_lib/eclipse-temurin:17.0.10_7-jdk-jammy</image>
                        </from>
                        <to>
                            <!--                            前缀名/命名空间/项目名:项目版本-->
                            <image>10.0.0.3/aioj/${project.artifactId}:${project.version}</image>
                            <tags>
                                <!--版本号-->
                                <tag>${project.version}</tag>
                            </tags>
                            <auth>
                                <username></username>
                                <password></password>
                            </auth>
                        </to>
                        <outputPaths>
                            <tar>
                                ${project.build.directory}/${project.artifactId}-${project.version}.tar</tar>
                        </outputPaths>
                        <!--容器相关的属性-->
                        <container>
                            <environment>
                                <TZ>Asia/Shanghai</TZ>
                                <PROFILES_ACTIVE>${docker.spring.active}</PROFILES_ACTIVE>
                            </environment>
                            <!--jvm内存参数-->
                            <jvmFlags>
                                <jvmFlag>-Xms512m</jvmFlag>
                                <jvmFlag>-Xmx512m</jvmFlag>
                            </jvmFlags>
                        </container>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>build</goal>
                                <goal>buildTar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <profiles>
        <!--开发环境-->
        <profile>
            <id>dev</id>
            <properties>
                <env>dev</env>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <!-- 测试环境 -->
        <profile>
            <id>test</id>
            <properties>
                <env>test</env>
            </properties>
        </profile>
        <!--生产环境-->
        <profile>
            <id>prod</id>
            <properties>
                <env>prod</env>
            </properties>
        </profile>
    </profiles>

</project>