<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF licenses this file to You 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>org.apache.kyuubi</groupId>
        <artifactId>kyuubi-parent</artifactId>
        <version>1.4.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <!--
       A scala-free module in runtime scope.
       -->
    <artifactId>kyuubi-hive-jdbc</artifactId>
    <name>Kyuubi Project Hive JDBC Client</name>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-storage-api</artifactId>
            <version>${hive.jdbc.storage-api.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-service-rpc</artifactId>
            <version>${hive.jdbc.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.hive.shims</groupId>
            <artifactId>hive-shims-common</artifactId>
            <version>${hive.jdbc.version}</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.hive.shims</groupId>
            <artifactId>hive-shims-0.23</artifactId>
            <version>${hive.jdbc.version}</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-common</artifactId>
            <version>${hive.jdbc.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-metastore</artifactId>
            <version>${hive.jdbc.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-serde</artifactId>
            <version>${hive.jdbc.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-service</artifactId>
            <version>${hive.jdbc.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-jdbc</artifactId>
            <version>${hive.jdbc.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>${hive.jdbc.commons-codec.version}</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>${hive.jdbc.commons-lang.version}</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${hive.jdbc.guava.version}</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>${hive.jdbc.curator.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-client</artifactId>
            <version>${hive.jdbc.curator.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${hive.jdbc.httpcomponents-client.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>${hive.jdbc.httpcomponents-core.version}</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.apache.thrift</groupId>
            <artifactId>libthrift</artifactId>
            <version>${hive.jdbc.thrift.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.thrift</groupId>
            <artifactId>libfb303</artifactId>
            <version>${hive.jdbc.fb303.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>${hive.jdbc.zookeeper.version}</version>
            <optional>true</optional>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client-api</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <configuration>
                    <minimizeJar>true</minimizeJar>
                    <createSourcesJar>true</createSourcesJar>
                    <shadeSourcesContent>true</shadeSourcesContent>
                    <shadedArtifactAttached>false</shadedArtifactAttached>
                    <artifactSet>
                        <excludes>
                            <exclude>org.apache.hadoop:*</exclude>
                            <exclude>org.slf4j:*</exclude>
                        </excludes>
                    </artifactSet>
                    <filters>
                        <filter>
                            <artifact>commons-codec:commons-codec</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>commons-lang:commons-lang</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>com.google.guava:guava</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive:hive-metastore</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                                <exclude>package.jdo</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive:hive-storage-api</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive:hive-service-rpc</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive:hive-shims</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive.shims:hive-shims-common</artifact>
                            <includes>
                                <include>**</include>
                            </includes>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive.shims:hive-shims-0.23</artifact>
                            <includes>
                                <include>**</include>
                            </includes>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive:hive-common</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive:hive-serde</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive:hive-service</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                                <exclude>hive-webapps/**</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.hive:hive-jdbc</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                                <exclude>META-INF/services/*</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.curator:curator-client</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.curator:curator-framework</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.httpcomponents:httpclient</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.httpcomponents:httpcore</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.thrift:libfb303</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.thrift:libthrift</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>org.apache.zookeeper:zookeeper</artifact>
                            <excludes>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                                <exclude>LICENSE.txt</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                                <exclude>META-INF/DEPENDENCIES</exclude>
                                <exclude>META-INF/maven/**</exclude>
                                <exclude>mozilla/**</exclude>
                                <exclude>*.properties</exclude>
                            </excludes>
                        </filter>
                    </filters>
                    <relocations>
                        <relocation>
                            <pattern>com.facebook</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.com.facebook</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>com.google.common</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.com.google.common</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.commons.codec</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.commons.codec</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.commons.lang</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.commons.lang</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.curator</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.curator</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.hadoop.hive</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.hadoop.hive</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.hive</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.hive</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.http</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.http</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.jute</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.jute</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.thrift</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.thrift</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>org.apache.zookeeper</pattern>
                            <shadedPattern>${kyuubi.shade.packageName}.org.apache.zookeeper</shadedPattern>
                        </relocation>
                    </relocations>
                    <transformers>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer"/>
                    </transformers>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--
              This is to ensure references to shaded Hive classes can be resolved in IDEs such as Intellij.
              For reference: https://youtrack.jetbrains.com/issue/IDEA-126596
              -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${basedir}/target/${project.artifactId}-${project.version}.jar</file>
                                    <type>jar</type>
                                    <classifier>optional</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
