<?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">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-parent_2.13</artifactId>
    <version>4.1.0-preview4</version>
    <relativePath>../../../../pom.xml</relativePath>
  </parent>

  <artifactId>spark-connect-client-jdbc_2.13</artifactId>
  <packaging>jar</packaging>
  <name>Spark Project Connect JDBC Driver</name>
  <url>https://spark.apache.org/</url>
  <properties>
    <sbt.project.name>connect-client-jdbc</sbt.project.name>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-connect-common_${scala.binary.version}</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql-api_${scala.binary.version}</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-connect-shims_${scala.binary.version}</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sketch_${scala.binary.version}</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-compiler</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.scala-lang.modules</groupId>
      <artifactId>scala-xml_${scala.binary.version}</artifactId>
      <scope>compile</scope>
    </dependency>
    <!--
      We need to define protobuf here because we need to change the scope of both from
      provided to compile. If we don't do this we can't shade these libraries.
    -->
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>failureaccess</artifactId>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-tags_${scala.binary.version}</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.scalacheck</groupId>
      <artifactId>scalacheck_${scala.binary.version}</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql-api_${scala.binary.version}</artifactId>
      <version>${project.version}</version>
      <classifier>tests</classifier>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-common-utils_${scala.binary.version}</artifactId>
      <version>${project.version}</version>
      <classifier>tests</classifier>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-connect-client-jvm_${scala.binary.version}</artifactId>
      <version>${project.version}</version>
      <classifier>tests</classifier>
      <scope>test</scope>
    </dependency>
    <!-- Use mima to perform the compatibility check -->
    <dependency>
      <groupId>com.typesafe</groupId>
      <artifactId>mima-core_${scala.binary.version}</artifactId>
      <version>${mima.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory>
    <testOutputDirectory>target/scala-${scala.binary.version}/test-classes</testOutputDirectory>
    <plugins>
      <plugin>
        <groupId>org.scalatest</groupId>
        <artifactId>scalatest-maven-plugin</artifactId>
        <configuration>
          <argLine>-ea -Xmx4g -Xss4m -XX:MaxMetaspaceSize=2g -XX:ReservedCodeCacheSize=${CodeCacheSize} ${extraJavaTestArgs} -Darrow.memory.debug.allocator=true</argLine>
        </configuration>
      </plugin>
      <!-- Shade all Guava / Protobuf / Netty dependencies of this build -->
      <!-- TODO (SPARK-42449): Ensure shading rules are handled correctly in `native-image.properties` and support GraalVM   -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <configuration combine.self = "override">
          <shadedArtifactAttached>false</shadedArtifactAttached>
          <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
          <artifactSet>
            <includes>
              <include>org.apache.spark:spark-connect-client-jdbc_${scala.binary.version}</include>
            </includes>
          </artifactSet>
          <relocations>
            <relocation>
              <pattern>com.google.common</pattern>
              <shadedPattern>${spark.shade.packageName}.connect.guava</shadedPattern>
              <includes>
                <include>com.google.common.**</include>
              </includes>
            </relocation>
            <relocation>
              <pattern>io.grpc</pattern>
              <shadedPattern>${spark.shade.packageName}.io.grpc</shadedPattern>
              <includes>
                <include>io.grpc.**</include>
              </includes>
            </relocation>
            <relocation>
              <pattern>com.google</pattern>
              <shadedPattern>${spark.shade.packageName}.com.google</shadedPattern>
              <excludes>
                <!-- Guava is relocated to ${spark.shade.packageName}.connect.guava -->
                <exclude>com.google.common.**</exclude>
              </excludes>
            </relocation>
            <relocation>
              <pattern>io.netty</pattern>
              <shadedPattern>${spark.shade.packageName}.io.netty</shadedPattern>
            </relocation>
            <relocation>
              <pattern>io.perfmark</pattern>
              <shadedPattern>${spark.shade.packageName}.io.perfmark</shadedPattern>
            </relocation>
            <relocation>
              <pattern>org.codehaus</pattern>
              <shadedPattern>${spark.shade.packageName}.org.codehaus</shadedPattern>
            </relocation>
            <relocation>
              <pattern>org.apache.arrow</pattern>
              <shadedPattern>${spark.shade.packageName}.org.apache.arrow</shadedPattern>
            </relocation>
            <relocation>
              <pattern>android.annotation</pattern>
              <shadedPattern>${spark.shade.packageName}.android.annotation</shadedPattern>
            </relocation>
          </relocations>
          <!--SPARK-42228: Add `ServicesResourceTransformer` to relocation class names in META-INF/services for grpc-->
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
          </transformers>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare-test-jar</id>
            <phase>test-compile</phase>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
