<?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>

    <groupId>io.github.fluxsce</groupId>
    <artifactId>flux-service-center-sdk</artifactId>
    <version>2.0.3</version>
    <packaging>jar</packaging>

    <name>Flux Service Center SDK</name>
    <description>Java SDK for Flux Service Registration and Configuration Center</description>
    <url>https://github.com/fluxsce/flux-service-center-sdk-java</url>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>Flux Team</name>
            <email>team@fluxsce.com</email>
            <organization>Fluxsce</organization>
            <organizationUrl>https://github.com/fluxsce</organizationUrl>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/fluxsce/flux-service-center-sdk-java.git</connection>
        <developerConnection>scm:git:ssh://github.com:fluxsce/flux-service-center-sdk-java.git</developerConnection>
        <url>https://github.com/fluxsce/flux-service-center-sdk-java/tree/main</url>
    </scm>

    <distributionManagement>
        <repository>
            <id>central</id>
            <url>https://central.sonatype.com/api/v1/publisher</url>
        </repository>
    </distributionManagement>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        
        <!-- 发布控制（参考 fastjson） -->
        <!-- 平时开发跳过，发布时使用 -Dgpg.skip=false -Djavadoc.skip=false -->
        <gpg.skip>true</gpg.skip>
        <javadoc.skip>false</javadoc.skip>
        
        <!-- Dependency versions -->
        <!-- gRPC 1.54.2 兼容 CentOS 7, protobuf 3.25.8 无安全漏洞 -->
        <grpc.version>1.54.2</grpc.version>
        <protobuf.version>3.25.8</protobuf.version>
        <slf4j.version>2.0.16</slf4j.version>
        <junit5.version>5.11.3</junit5.version>
        <mockito.version>5.14.2</mockito.version>
    </properties>

    <dependencies>
        <!-- gRPC dependencies -->
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-netty-shaded</artifactId>
            <version>${grpc.version}</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
            <version>${grpc.version}</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-stub</artifactId>
            <version>${grpc.version}</version>
        </dependency>
        
        <!-- Protobuf -->
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>${protobuf.version}</version>
        </dependency>
        
        <!-- Annotation for gRPC -->
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>annotations-api</artifactId>
            <version>6.0.53</version>
            <scope>provided</scope>
        </dependency>
        
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        
        <!-- Test dependencies -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        
        <!-- JUnit 5 (Jupiter) - 用于更现代的测试 -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit5.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit5.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>${junit5.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>${slf4j.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.7.1</version>
            </extension>
        </extensions>
        
        <plugins>
            <!-- OS Maven Plugin - Ensure it runs to set os.detected.classifier -->
            <plugin>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.7.1</version>
                <executions>
                    <execution>
                        <id>detect-os</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>detect</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <!-- Maven Compiler Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            
            <!-- Protobuf Maven Plugin -->
            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>0.6.1</version>
                <configuration>
                    <!-- Protoc 编译器（根据操作系统自动选择） -->
                    <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
                    <!-- Proto 文件源目录 -->
                    <protoSourceRoot>${project.basedir}/src/main/proto</protoSourceRoot>
                </configuration>
                <executions>
                    <!-- 生成 Proto 消息类 -->
                    <execution>
                        <id>compile-protobuf</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <!-- Proto 消息类输出到 java 目录 -->
                            <outputDirectory>${project.build.directory}/generated-sources/protobuf/java</outputDirectory>
                        </configuration>
                    </execution>
                    <!-- 生成 gRPC 服务类 -->
                    <execution>
                        <id>compile-grpc</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>compile-custom</goal>
                        </goals>
                        <configuration>
                            <!-- gRPC Java 插件 -->
                            <pluginId>grpc-java</pluginId>
                            <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
                            <!-- gRPC 服务类输出到 grpc-java 目录 -->
                            <outputDirectory>${project.build.directory}/generated-sources/protobuf/grpc-java</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
            <!-- Build Helper Maven Plugin - 确保 IDE 识别生成的源代码 -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <execution>
                        <id>add-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <!-- Proto 消息类源码目录 -->
                                <source>${project.build.directory}/generated-sources/protobuf/java</source>
                                <!-- gRPC 服务类源码目录 -->
                                <source>${project.build.directory}/generated-sources/protobuf/grpc-java</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            
            <!-- Maven Source Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <!-- Maven Surefire Plugin - 支持 JUnit 5 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.5.2</version>
                <configuration>
                    <!-- 支持 JUnit 4 和 JUnit 5 并存 -->
                    <includes>
                        <include>**/*Test.java</include>
                        <include>**/*Tests.java</include>
                    </includes>
                </configuration>
            </plugin>
            
            <!-- Maven Javadoc Plugin - 生成 Javadoc JAR（发布到 Maven 中央仓库必需） -->
            <!-- 参考 fastjson：使用 javadoc.skip 属性控制 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.6.3</version>
                <configuration>
                    <skip>${javadoc.skip}</skip>
                    <encoding>UTF-8</encoding>
                    <charset>UTF-8</charset>
                    <docencoding>UTF-8</docencoding>
                    <!-- 完全禁用 Javadoc 检查（解决 HTML 实体问题） -->
                    <doclint>none</doclint>
                    <failOnError>false</failOnError>
                    <!-- 排除 protobuf 生成的源文件 -->
                    <sourceFileExcludes>
                        <exclude>**/target/generated-sources/**/*.java</exclude>
                    </sourceFileExcludes>
                    <!-- 额外的 JVM 选项 -->
                    <additionalJOptions>
                        <additionalJOption>-J-Duser.language=en</additionalJOption>
                        <additionalJOption>-J-Duser.country=US</additionalJOption>
                        <additionalJOption>-J-Xmx512m</additionalJOption>
                    </additionalJOptions>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <!-- Maven GPG Plugin - GPG 签名（发布到 Maven 中央仓库必需） -->
            <!-- 参考 fastjson：使用 gpg.skip 属性控制，默认跳过 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <skip>${gpg.skip}</skip>
                    <!-- Windows keyboxd 兼容配置 -->
                    <gpgArguments>
                        <arg>--pinentry-mode</arg>
                        <arg>loopback</arg>
                        <arg>--batch</arg>
                        <arg>--yes</arg>
                        <arg>--no-tty</arg>
                    </gpgArguments>
                    <useAgent>false</useAgent>
                </configuration>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <!-- Central Publishing Maven Plugin - 发布到 Maven 中央仓库 (2024新方式) -->
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.8.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>true</autoPublish>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

