<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~  Copyright 1999-2019 Seata.io Group.
  ~
  ~  Licensed under the Apache License, Version 2.0 (the "License");
  ~  you may not use this file except in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~       http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing, software
  ~  distributed under the License is distributed on an "AS IS" BASIS,
  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~  See the License for the specific language governing permissions and
  ~  limitations under the License.
  -->
<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">
    <parent>
        <groupId>io.seata</groupId>
        <artifactId>seata-parent</artifactId>
        <version>${revision}</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>seata-server</artifactId>
    <packaging>jar</packaging>
    <name>seata-server ${project.version}</name>
    <description>server for Seata built with Maven</description>

    <properties>
        <spring-boot-for-server.version>${spring-boot.version}</spring-boot-for-server.version>
        <spring-framework-for-server.version>${spring-framework.version}</spring-framework-for-server.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- junit5 -->
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>${junit-jupiter.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- spring-framework-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <version>${spring-framework-for-server.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- spring-boot -->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot-for-server.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-framework-bom</artifactId>
                    </exclusion>
                </exclusions>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- springboot web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>log4j-to-slf4j</artifactId>
                    <groupId>org.apache.logging.log4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-spring-autoconfigure-server</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-core</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-config-all</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>log4j</artifactId>
                    <groupId>log4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-discovery-all</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-serializer-all</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-compressor-all</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-metrics-all</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>seata-console</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!-- for database -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
       <!--  if you run seata-server in IDE and use mysql8 as session store, please rewrite version to ${mysql8.jdbc.version}-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <!-- Copyright restrictions, do not reference this dependency.
             You can add this dependency to the '/seata/lib' directory of the seata-server when necessary.
        <dependency>
            <groupId>com.oracle.ojdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>${ojdbc.version}</version>
        </dependency>-->

        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
        </dependency>

        <!-- only for event bus -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>

        <!-- jedis -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.microwww</groupId>
            <artifactId>redis-server</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
        </dependency>

        <!-- logback -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
        </dependency>
        <!-- logback appenders -->
        <dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.danielwegener</groupId>
            <artifactId>logback-kafka-appender</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <silent>true</silent>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <!--resolve slf4j-simple conflicts-->
                            <includeScope>runtime</includeScope>
                            <excludeGroupIds>org.apache.logging.log4j,log4j,mysql</excludeGroupIds>
                            <skip>${dependencies.copy.skip}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-mysql</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>mysql</groupId>
                                    <artifactId>mysql-connector-java</artifactId>
                                    <version>${mysql.jdbc.version}</version>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>mysql</groupId>
                                    <artifactId>mysql-connector-java</artifactId>
                                    <version>${mysql8.jdbc.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>
                                ${project.build.directory}/lib/jdbc
                            </outputDirectory>
                            <skip>${dependencies.copy.skip}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>${jib-maven-plugin.version}</version>
                <configuration>
                    <from>
                        <image>${IMAGE_NAME}</image>
                        <platforms>
                            <platform>
                                <os>linux</os>
                                <architecture>amd64</architecture>
                            </platform>
                            <platform>
                                <os>linux</os>
                                <architecture>arm64</architecture>
                            </platform>
                        </platforms>
                    </from>
                    <to>
                        <image>docker.io/seataio/seata-server</image>
                        <tags>${image.tags}</tags>
                        <auth>
                            <username>${REGISTRY_USERNAME}</username>
                            <password>${REGISTRY_PASSWORD}</password>
                        </auth>
                    </to>
                    <container>
                        <appRoot>/seata-server</appRoot>
                        <workingDirectory>/seata-server</workingDirectory>
                        <mainClass>io.seata.server.ServerApplication</mainClass>
                        <ports>
                            <port>8091</port>
                            <port>7091</port>
                        </ports>
                        <jvmFlags>
                            <jvmFlag>-Djava.security.egd=file:/dev/./urandom</jvmFlag>
                            <jvmFlag>-server</jvmFlag>
                            <jvmFlag>-Xss512k</jvmFlag>
                            <jvmFlag>-XX:+UnlockExperimentalVMOptions</jvmFlag>
                            <jvmFlag>-XX:+UseContainerSupport</jvmFlag>
                            <jvmFlag>-XX:SurvivorRatio=10</jvmFlag>
                            <jvmFlag>-XX:MetaspaceSize=128m</jvmFlag>
                            <jvmFlag>-XX:MaxMetaspaceSize=256m</jvmFlag>
                            <jvmFlag>-XX:MaxDirectMemorySize=256m</jvmFlag>
                            <jvmFlag>-XX:-OmitStackTraceInFastThrow</jvmFlag>
                            <jvmFlag>-XX:-UseAdaptiveSizePolicy</jvmFlag>
                            <jvmFlag>-XX:+HeapDumpOnOutOfMemoryError</jvmFlag>
                            <jvmFlag>-XX:HeapDumpPath=/var/log/seata_heapdump.hprof</jvmFlag>
                            <!--gc-->
                            <jvmFlag>-XX:+DisableExplicitGC</jvmFlag>
                            <jvmFlag>-XX:+UseG1GC</jvmFlag>
                            <!--netty-->
                            <jvmFlag>-Dio.netty.leakDetectionLevel=advanced</jvmFlag>
                            <!--log-->
                            <jvmFlag>-Dlogback.color.disable-for-bat=true</jvmFlag>
                        </jvmFlags>
                        <labels>
                            <name>seata-server</name>
                        </labels>
                        <creationTime>USE_CURRENT_TIMESTAMP</creationTime>
                    </container>
                    <extraDirectories>
                        <paths>
                            <path>
                                <from>target/lib/jdbc</from>
                                <into>/seata-server/libs/jdbc</into>
                            </path>
                        </paths>
                    </extraDirectories>
                    <skip>${image.publish.skip}</skip>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release-seata</id>
            <properties>
                <mysql.jdbc.version>5.1.35</mysql.jdbc.version>
                <mysql8.jdbc.version>8.0.27</mysql8.jdbc.version>
                <dependencies.copy.skip>false</dependencies.copy.skip>
            </properties>
            <build>
                <finalName>seata-server</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <version>${spring-boot.version}</version>
                        <configuration>
                            <mainClass>io.seata.server.ServerApplication</mainClass>
                            <layout>ZIP</layout>
                            <attach>false</attach>
                            <includes>
                                <include>
                                    <groupId>null</groupId>
                                    <artifactId>null</artifactId>
                                </include>
                            </includes>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>repackage</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
