<?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>com.lancedb</groupId>
    <artifactId>lance-spark-root</artifactId>
    <version>0.0.3</version>
    <packaging>pom</packaging>

    <name>${project.artifactId}</name>
    <description>Lance Spark Connector</description>
    <url>https://lancedb.github.io/lance-spark</url>

    <developers>
        <developer>
            <name>Lance DB Dev Group</name>
            <email>dev@lancedb.com</email>
        </developer>
    </developers>

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

    <scm>
        <connection>scm:git:git@github.com:lancedb/lance-spark.git</connection>
        <developerConnection>scm:git:git@github.com:lancedb/lance-spark.git</developerConnection>
        <url>git@github.com:lancedb/lance-spark.git</url>
        <tag>HEAD</tag>
    </scm>

    <issueManagement>
        <system>GitHub</system>
        <url>https://github.com/lancedb/lance-spark/issues</url>
    </issueManagement>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <properties>
        <lance-spark.version>0.0.3</lance-spark.version>
        <lance.version>0.26.1</lance.version>
        <lance-namespace.version>0.0.5</lance-namespace.version>

        <spark34.version>3.4.4</spark34.version>
        <spark35.version>3.5.5</spark35.version>
        <spark40.version>4.0.0</spark40.version>
        <spark.version>${spark35.version}</spark.version>

        <spark34.compat.version>3.4</spark34.compat.version>
        <spark35.compat.version>3.5</spark35.compat.version>
        <spark40.compat.version>4.0</spark40.compat.version>
        <spark.compat.version>${spark35.compat.version}</spark.compat.version>

        <scala212.version>2.12.20</scala212.version>
        <scala213.version>2.13.16</scala213.version>
        <scala.version>${scala212.version}</scala.version>

        <scala212.compat.version>2.12</scala212.compat.version>
        <scala213.compat.version>2.13</scala213.compat.version>
        <scala.compat.version>${scala212.compat.version}</scala.compat.version>

        <spotless.skip>false</spotless.skip>
        <spotless.version>2.30.0</spotless.version>
        <spotless.java.googlejavaformat.version>1.7</spotless.java.googlejavaformat.version>
        <!-- Please also update .scalafmt.conf when you change it here -->
        <spotless.scala.scalafmt.version>3.7.5</spotless.scala.scalafmt.version>
        <spotless.delimiter>package</spotless.delimiter>
        <spotless.license.header>
            /*
            * 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.
            */
        </spotless.license.header>

        <junit.version>5.10.1</junit.version>
        <scalatest.version>3.2.10</scalatest.version>

        <scala-maven-plugin.version>3.2.1</scala-maven-plugin.version>
        <maven-dependency-plugin.version>3.6.1</maven-dependency-plugin.version>
        <maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version>
        <maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
        <maven-source-plugin.version>2.2.1</maven-source-plugin.version>
        <maven-javadoc-plugin.version>2.9.1</maven-javadoc-plugin.version>
        <maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
        <maven-release-plugin.version>3.1.0</maven-release-plugin.version>
        <maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
        <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
        <maven-install-plugin.version>2.5.2</maven-install-plugin.version>
        <maven-resources-plugin.version>3.0.2</maven-resources-plugin.version>
        <maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
    </properties>

    <modules>
        <module>lance-spark-base_2.12</module>
        <module>lance-spark-3.5_2.12</module>
        <module>lance-spark-bundle-3.5_2.12</module>
        <module>lance-spark-3.4_2.12</module>
        <module>lance-spark-bundle-3.4_2.12</module>
        <module>lance-spark-base_2.13</module>
        <module>lance-spark-3.5_2.13</module>
        <module>lance-spark-bundle-3.5_2.13</module>
        <module>lance-spark-3.4_2.13</module>
        <module>lance-spark-bundle-3.4_2.13</module>
        <module>lance-spark-4.0_2.13</module>
        <module>lance-spark-bundle-4.0_2.13</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <!-- Each version module should explicitly overwrite the Spark related dependency versions -->
            <dependency>
                <groupId>org.apache.spark</groupId>
                <artifactId>spark-sql_${scala.compat.version}</artifactId>
                <version>${spark.version}</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.lancedb</groupId>
            <artifactId>lance-core</artifactId>
            <version>${lance.version}</version>
        </dependency>
        <dependency>
            <groupId>com.lancedb</groupId>
            <artifactId>lance-namespace-core</artifactId>
            <version>${lance-namespace.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_${scala.compat.version}</artifactId>
            <version>${scalatest.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${maven-source-plugin.version}</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>${maven-javadoc-plugin.version}</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${maven-checkstyle-plugin.version}</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <consoleOutput>true</consoleOutput>
                    <failsOnError>true</failsOnError>
                    <violationSeverity>warning</violationSeverity>
                    <linkXRef>false</linkXRef>
                </configuration>
                <executions>
                    <execution>
                        <id>validate</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>${maven-release-plugin.version}</version>
                <configuration>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.7.0</version>
            </extension>
        </extensions>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>${maven-clean-plugin.version}</version>
                </plugin>
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>${maven-resources-plugin.version}</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <compilerArgs>
                            <arg>-h</arg>
                            <arg>target/headers</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${maven-jar-plugin.version}</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>${maven-install-plugin.version}</version>
                </plugin>
                <plugin>
                    <groupId>com.diffplug.spotless</groupId>
                    <artifactId>spotless-maven-plugin</artifactId>
                    <version>${spotless.version}</version>
                    <configuration>
                        <skip>${spotless.skip}</skip>
                        <upToDateChecking>
                            <enabled>true</enabled>
                        </upToDateChecking>
                        <java>
                            <includes>
                                <include>src/main/java/**/*.java</include>
                                <include>src/test/java/**/*.java</include>
                            </includes>
                            <googleJavaFormat>
                                <version>${spotless.java.googlejavaformat.version}</version>
                                <style>GOOGLE</style>
                            </googleJavaFormat>

                            <importOrder>
                                <order>com.lancedb.lance,,javax,java,\#</order>
                            </importOrder>

                            <removeUnusedImports />
                        </java>
                        <scala>
                            <includes>
                                <include>src/main/scala/**/*.scala</include>
                                <include>src/main/scala-*/**/*.scala</include>
                                <include>src/test/scala/**/*.scala</include>
                                <include>src/test/scala-*/**/*.scala</include>
                            </includes>
                            <scalafmt>
                                <version>${spotless.scala.scalafmt.version}</version>
                                <scalaMajorVersion>${scala.compat.version}</scalaMajorVersion>
                                <file>.scalafmt.conf</file>
                            </scalafmt>
                        </scala>
                        <licenseHeader>
                            <content>${spotless.license.header}</content>
                            <delimiter>${spotless.delimiter}</delimiter>
                        </licenseHeader>
                    </configuration>
                    <executions>
                        <execution>
                            <id>spotless-check</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>apply</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <profiles>
        <profile>
            <id>jdk8</id>
            <activation>
                <jdk>[1.8,1.8.999]</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
            </properties>
        </profile>
        <profile>
            <id>jdk11+</id>
            <activation>
                <jdk>[11,)</jdk>
            </activation>
            <properties>
                <!-- Ping release target to JDK8 to link only against Java 8 APIs -->
                <maven.compiler.release>8</maven.compiler.release>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>${maven-surefire-plugin.version}</version>
                        <configuration>
                            <argLine>
                                -XX:+IgnoreUnrecognizedVMOptions
                                --add-opens=java.base/java.lang=ALL-UNNAMED
                                --add-opens=java.base/java.lang.invoke=ALL-UNNAMED
                                --add-opens=java.base/java.lang.reflect=ALL-UNNAMED
                                --add-opens=java.base/java.io=ALL-UNNAMED
                                --add-opens=java.base/java.net=ALL-UNNAMED
                                --add-opens=java.base/java.nio=ALL-UNNAMED
                                --add-opens=java.base/java.util=ALL-UNNAMED
                                --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
                                --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED
                                --add-opens=java.base/jdk.internal.ref=ALL-UNNAMED
                                --add-opens=java.base/sun.nio.ch=ALL-UNNAMED
                                --add-opens=java.base/sun.nio.cs=ALL-UNNAMED
                                --add-opens=java.base/sun.security.action=ALL-UNNAMED
                                --add-opens=java.base/sun.util.calendar=ALL-UNNAMED
                                --add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED
                                -Djdk.reflect.useDirectMethodHandle=false
                                -Dio.netty.tryReflectionSetAccessible=true
                            </argLine>
                            <forkNode
                                    implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory" />
                            <useSystemClassLoader>false</useSystemClassLoader>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>scala-2.12</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <scala.version>${scala212.version}</scala.version>
                <scala.compat.version>${scala212.compat.version}</scala.compat.version>
            </properties>
        </profile>
        <profile>
            <id>scala-2.13</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <scala.version>${scala213.version}</scala.version>
                <scala.compat.version>${scala213.compat.version}</scala.compat.version>
            </properties>
        </profile>
        <profile>
            <id>spark-3.4</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <spark.version>${spark34.version}</spark.version>
                <spark.compat.version>${spark34.compat.version}</spark.compat.version>
            </properties>
        </profile>
        <profile>
            <id>spark-3.5</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <spark.version>${spark35.version}</spark.version>
                <spark.compat.version>${spark35.compat.version}</spark.compat.version>
            </properties>
        </profile>
        <profile>
            <id>spark-4.0</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <spark.version>${spark40.version}</spark.version>
                <spark.compat.version>${spark40.compat.version}</spark.compat.version>
            </properties>
        </profile>
        <profile>
            <id>deploy-to-ossrh</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.central</groupId>
                        <artifactId>central-publishing-maven-plugin</artifactId>
                        <version>0.4.0</version>
                        <extensions>true</extensions>
                        <configuration>
                            <publishingServerId>ossrh</publishingServerId>
                            <tokenAuth>true</tokenAuth>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.13</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
