<?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.daone-dadp</groupId>
    <artifactId>dadp-jdbc-wrapper</artifactId>
    <version>3.0.3</version>
    <packaging>jar</packaging>

    <name>DADP JDBC Wrapper</name>
    <description>DADP JDBC Wrapper Driver - DB 자동 암복호화 Proxy</description>
    <url>https://github.com/daone-dadp/dadp-jdbc-wrapper</url>

    <!-- 라이선스 정보 (필수) -->
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <!-- 개발자 정보 (필수) -->
    <developers>
        <developer>
            <name>dadp team</name>
            <email>csh@daonecns.co.kr</email>
        </developer>
    </developers>

    <!-- SCM 정보 (필수) -->
    <scm>
        <connection>scm:git:git://github.com/daone-dadp/dadp-jdbc-wrapper.git</connection>
        <developerConnection>scm:git:ssh://github.com/daone-dadp/dadp-jdbc-wrapper.git</developerConnection>
        <url>https://github.com/daone-dadp/dadp-jdbc-wrapper</url>
    </scm>

    <!-- 배포 설정 (Central Publishing 플러그인이 자동 처리) -->
    <distributionManagement>
        <snapshotRepository>
            <id>central</id>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>central</id>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring-boot.version>2.7.18</spring-boot.version>
        <jackson.version>2.13.5</jackson.version>
        <slf4j.version>1.7.36</slf4j.version>
        <junit.version>5.9.3</junit.version>
        <java.version>17</java.version>
        <classifier></classifier>
    </properties>

    <profiles>
        <!-- Java 8 프로파일 -->
        <profile>
            <id>java8</id>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <java.version>8</java.version>
                <classifier>java8</classifier>
            </properties>
        </profile>

        <!-- Java 11 프로파일 -->
        <profile>
            <id>java11</id>
            <properties>
                <maven.compiler.source>11</maven.compiler.source>
                <maven.compiler.target>11</maven.compiler.target>
                <java.version>11</java.version>
                <classifier>java11</classifier>
            </properties>
        </profile>

        <!-- Java 17 프로파일 (기본) -->
        <profile>
            <id>java17</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <maven.compiler.source>17</maven.compiler.source>
                <maven.compiler.target>17</maven.compiler.target>
                <java.version>17</java.version>
                <classifier>java17</classifier>
            </properties>
        </profile>
    </profiles>

    <dependencyManagement>
        <dependencies>
            <!-- Spring Boot BOM (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>
            
            <!-- Jackson 버전 관리 -->
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            
            <!-- SLF4J 버전 관리 -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            
            <!-- JUnit 버전 관리 -->
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter</artifactId>
                <version>${junit.version}</version>
            </dependency>
            
            <!-- Internal Dependencies -->
            <dependency>
                <groupId>io.github.daone-dadp</groupId>
                <artifactId>dadp-hub-crypto-lib</artifactId>
                <version>1.0.1</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- Hub 암복호화 라이브러리 (필수) - Java 버전별 classifier 사용 -->
        <dependency>
            <groupId>io.github.daone-dadp</groupId>
            <artifactId>dadp-hub-crypto-lib</artifactId>
            <version>1.0.1</version>
            <classifier>${classifier}</classifier>
        </dependency>
        
        <!-- Jackson for JSON processing -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        
        <!-- 
        DB 드라이버는 pom.xml에 포함하지 않음
        고객사가 lib 폴더에 필요한 드라이버 JAR를 직접 배치
        JDBC ServiceLoader 메커니즘이 클래스패스에서 자동으로 드라이버를 찾음
        테스트 시에도 lib 폴더의 드라이버를 사용하여 실제 운영 환경과 동일하게 테스트
        -->
        
        <!-- SLF4J for logging (provided scope: 앱에서 제공하는 버전 사용) -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        
        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- GPG 서명 플러그인 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <useAgent>false</useAgent>
                    <passphrase>${env.GPG_PASSPHRASE}</passphrase>
                    <skip>false</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- Central Publishing 플러그인 (공식 문서 기준) -->
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.7.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>false</autoPublish>
                    <waitUntil>validated</waitUntil>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

            <!-- Java 버전별 classifier로 JAR 생성 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <!-- 기본 JAR 생성 -->
                    <execution>
                        <id>default-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                    <!-- Classifier가 있는 JAR 생성 (classifier가 있을 때만) -->
                    <execution>
                        <id>classifier-jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <classifier>${classifier}</classifier>
                            <skipIfEmpty>true</skipIfEmpty>
                        </configuration>
                    </execution>
                </executions>
            </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>
            
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.5.0</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <!-- Fat JAR 빌드 (모든 의존성 포함, DB 드라이버 제외) -->
            <!-- 재빌드 없이 WAS 공통 라이브러리 디렉토리에 배치하여 사용 가능 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.5.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>all</shadedClassifierName>
                            <filters>
                                <!-- Spring/Servlet/SLF4J 등은 절대 포함 금지 -->
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <!-- Spring 관련 클래스 모두 제외 -->
                                        <exclude>org/springframework/**</exclude>
                                        <exclude>org/springframework/boot/**</exclude>
                                        <!-- Spring 관련 리소스 파일 제외 (충돌 방지) -->
                                        <exclude>META-INF/spring.factories</exclude>
                                        <exclude>META-INF/spring.handlers</exclude>
                                        <exclude>META-INF/spring.schemas</exclude>
                                        <exclude>META-INF/spring.tooling</exclude>
                                        <exclude>META-INF/spring-configuration-metadata.json</exclude>
                                        <exclude>META-INF/additional-spring-configuration-metadata.json</exclude>
                                        <!-- Servlet 관련 클래스 제외 (Java 버전별로 다름) -->
                                        <exclude>jakarta/servlet/**</exclude>
                                        <exclude>javax/servlet/**</exclude>
                                        <!-- Logback 구현체 제외 -->
                                        <exclude>ch/qos/logback/**</exclude>
                                        <!-- SLF4J API 제외 (앱에서 제공하는 버전 사용) -->
                                        <exclude>org/slf4j/**</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <!-- ServiceLoader 지원을 위한 META-INF/services 병합 -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <!-- MANIFEST.MF 병합 -->
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Built-By>DADP Development Team</Built-By>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                            <minimizeJar>true</minimizeJar>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
