<!-- Copyright 2018 ABSA Group Limited ~ ~ 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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>za.co.absa</groupId>
    <artifactId>abris_2.12</artifactId>
    <version>6.4.0</version>
    <name>abris</name>
    <description>Provides seamless integration between Avro and Spark Structured APIs.</description>
    <url>https://github.com/AbsaOSS/ABRiS</url>

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

    <!-- Confluent repository since their dependencies are not available in Maven Central -->
    <repositories>
        <repository>
            <id>confluent</id>
            <url>https://packages.confluent.io/maven/</url>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!--Maven-->
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.sources.version>3.0.1</maven.sources.version>
        <gpg.plugin.version>1.6</gpg.plugin.version>
        <surefire.version>3.0.0-M1</surefire.version>
        <nexus.staging.plugin.version>1.6.8</nexus.staging.plugin.version>
        <maven.shade.plugin.version>3.2.1</maven.shade.plugin.version>

        <!-- Spark -->
        <spark.default.version>3.2.4</spark.default.version>
        <avro.default.version>1.10.2</avro.default.version>
        <jackson.core.default.version>2.12.3</jackson.core.default.version>

        <!-- Cross build properties -->

        <default.scala.compat.version>2.12</default.scala.compat.version>
        <default.scala.version>${scala_2.12.version}</default.scala.version>

        <scala_2.12.version>2.12.10</scala_2.12.version>
        <scala_2.13.version>2.13.7</scala_2.13.version>

        <!-- Controlled by `scala-cross-build` plugin -->
        <scala.version>2.12.10</scala.version>
        <scala.compat.version>2.12</scala.compat.version>

        <!--Platforms-->
        <spark.version>${spark.default.version}</spark.version>
        <avro.version>${avro.default.version}</avro.version>
        <jackson.core.version>${jackson.core.default.version}</jackson.core.version>

        <spark.avro.version>${spark.version}</spark.avro.version>
        <kafka.spark.version>0-10</kafka.spark.version>
        <confluent.version>6.2.1</confluent.version>

        <!--Libs-->
        <jacoco.version>0.8.10</jacoco.version>

        <!--Tests-->
        <scalatestplus.mockito.version>3.1.2.0</scalatestplus.mockito.version>
        <scalatest.version>3.2.14</scalatest.version>
        <scalatest.maven.plugin.version>2.2.0</scalatest.maven.plugin.version>

        <scala.maven.plugin.version>3.3.2</scala.maven.plugin.version>

        <scm.url><!-- defined outside the pom --></scm.url>
        <scm.connection><!-- defined outside the pom --></scm.connection>
        <scm.developerConnection><!-- defined outside the pom --></scm.developerConnection>
    </properties>

    <scm>
        <url>${scm.url}</url>
        <connection>${scm.connection}</connection>
        <developerConnection>${scm.developerConnection}</developerConnection>
        <tag>v6.4.0</tag>
    </scm>

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

    <organization>
        <name>ABSA Group Limited</name>
        <url>https://www.absa.africa</url>
    </organization>

    <developers>
        <developer>
            <id>cerveada</id>
            <name>Adam Cervenka</name>
            <timezone>Europe/Prague</timezone>
            <url>https://github.com/cerveada</url>
        </developer>
        <developer>
            <id>kevinwallimann</id>
            <name>Kevin Wallimann</name>
            <timezone>Europe/Prague</timezone>
            <url>https://github.com/kevinwallimann</url>
        </developer>
    </developers>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro</artifactId>
                <version>${avro.version}</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>${jackson.core.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <!-- Tests -->
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_${scala.compat.version}</artifactId>
            <version>${scalatest.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalatestplus</groupId>
            <artifactId>mockito-3-2_${scala.compat.version}</artifactId>
            <version>${scalatestplus.mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Spark -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_${scala.compat.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_${scala.compat.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-streaming_${scala.compat.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-avro_${scala.compat.version}</artifactId>
            <version>${spark.avro.version}</version>
        </dependency>

        <!-- Spark Kafka -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql-kafka-${kafka.spark.version}_${scala.compat.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-streaming-kafka-${kafka.spark.version}_${scala.compat.version}</artifactId>
            <version>${spark.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Confluent's Kafka and Schema Registry -->
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>kafka-avro-serializer</artifactId>
            <version>${confluent.version}</version>
        </dependency>
        <dependency>
            <groupId>io.confluent</groupId>
            <artifactId>kafka-schema-registry-client</artifactId>
            <version>${confluent.version}</version>
        </dependency>

        <!-- Other -->
        <dependency>
            <groupId>za.co.absa.commons</groupId>
            <artifactId>commons_${scala.compat.version}</artifactId>
            <version>1.0.0</version>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
        <testSourceDirectory>src/test/scala</testSourceDirectory>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <!-- the Maven Scala plugin will compile Scala source files -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>${scala.maven.plugin.version}</version>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                    <scalaCompatVersion>${scala.compat.version}</scalaCompatVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>scala-compile</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!-- disable surefire -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire.version}</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>

            <!-- enable scalatest -->
            <plugin>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest-maven-plugin</artifactId>
                <version>${scalatest.maven.plugin.version}</version>
                <configuration>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <junitxml>.</junitxml>
                    <filereports>TestSuite.txt</filereports>
                </configuration>
                <executions>
                    <execution>
                        <id>test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.github.wajda</groupId>
                <artifactId>scala-cross-build-maven-plugin</artifactId>
                <version>0.2.1</version>
                <configuration>
                    <scalaBinaryVersionProperty>scala.compat.version</scalaBinaryVersionProperty>
                    <scalaVersionProperty>scala.version</scalaVersionProperty>
                    <defaultScalaBinaryVersion>${default.scala.compat.version}</defaultScalaBinaryVersion>
                    <defaultScalaVersion>${default.scala.version}</defaultScalaVersion>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <excludes>
                        <exclude>log4j.properties</exclude>
                    </excludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.scalastyle</groupId>
                <artifactId>scalastyle-maven-plugin</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <verbose>false</verbose>
                    <failOnViolation>true</failOnViolation>
                    <failOnWarning>false</failOnWarning>
                    <includeTestSourceDirectory>false</includeTestSourceDirectory>
                    <sourceDirectory>${project.basedir}/src/main/scala</sourceDirectory>
                    <testSourceDirectory>${project.basedir}/src/test/scala</testSourceDirectory>
                    <configLocation>${project.basedir}/scalastyle-config.xml</configLocation>
                    <outputFile>${project.basedir}/target/scalastyle-output.xml</outputFile>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro-maven-plugin</artifactId>
                <version>1.9.2</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>schema</goal>
                        </goals>
                        <configuration>
                            <sourceDirectory>src/main/avro/</sourceDirectory>
                            <outputDirectory>${project.basedir}/target/generated-sources/avro</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


    <profiles>

        <!-- Cross-building profiles -->
        <profile>
            <id>scala-2.12</id>
            <properties>
                <scala.compat.version>2.12</scala.compat.version>
                <scala.version>${scala_2.12.version}</scala.version>
            </properties>
        </profile>

        <profile>
            <id>scala-2.13</id>
            <properties>
                <scala.compat.version>2.13</scala.compat.version>
                <scala.version>${scala_2.13.version}</scala.version>
            </properties>
        </profile>

        <!-- Spark profiles -->
        <profile>
            <id>spark-3.2</id>
            <properties>
                <spark.version>${spark.default.version}</spark.version>
                <avro.version>${avro.default.version}</avro.version>
                <jackson.core.version>${jackson.core.default.version}</jackson.core.version>
            </properties>

        </profile>
        <profile>
            <id>spark-3.3</id>
            <properties>
                <spark.version>3.3.4</spark.version>
                <avro.version>1.11.0</avro.version>
                <jackson.core.version>2.13.4</jackson.core.version>
            </properties>
        </profile>
        <profile>
            <id>spark-3.4</id>
            <properties>
                <spark.version>3.4.2</spark.version>
                <avro.version>1.11.1</avro.version>
                <jackson.core.version>2.14.2</jackson.core.version>
            </properties>
        </profile>
        <profile>
            <id>spark-3.5</id>
            <properties>
                <spark.version>3.5.0</spark.version>
                <avro.version>1.11.2</avro.version>
                <jackson.core.version>2.15.2</jackson.core.version>
            </properties>
        </profile>
        <profile>
            <id>uber</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-shade-plugin</artifactId>
                        <version>${maven.shade.plugin.version}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>shade</goal>
                                </goals>
                                <configuration>
                                    <filters>
                                        <filter>
                                            <artifact>*:*</artifact>
                                            <excludes>
                                                <exclude>META-INF/*.SF</exclude>
                                                <exclude>META-INF/*.DSA</exclude>
                                                <exclude>META-INF/*.RSA</exclude>
                                            </excludes>
                                        </filter>
                                    </filters>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>deploy</id> <!-- deploy to maven central -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>${maven.sources.version}</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>net.alchim31.maven</groupId>
                        <artifactId>scala-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>doc-jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>${gpg.plugin.version}</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <!-- Prevent `gpg` from using pinentry programs -->
                            <gpgArguments>
                                <arg>--pinentry-mode</arg>
                                <arg>loopback</arg>
                            </gpgArguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>${nexus.staging.plugin.version}</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                            <autoDropAfterRelease>true</autoDropAfterRelease>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>release</id> <!-- increment version and create release commits -->
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-release-plugin</artifactId>
                        <version>2.5.3</version>
                        <configuration>
                            <tagNameFormat>v@{project.version}</tagNameFormat>
                            <providerImplementations>
                                <git>jgit</git>
                            </providerImplementations>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.maven.scm</groupId>
                                <artifactId>maven-scm-api</artifactId>
                                <version>1.11.2</version>
                            </dependency>
                            <dependency>
                                <groupId>org.apache.maven.scm</groupId>
                                <artifactId>maven-scm-provider-jgit</artifactId>
                                <version>1.11.2</version>
                            </dependency>
                            <dependency>
                                <groupId>org.eclipse.jgit</groupId>
                                <artifactId>org.eclipse.jgit</artifactId>
                                <version>5.5.1.201910021850-r</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>license-check</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.rat</groupId>
                        <artifactId>apache-rat-plugin</artifactId>
                        <version>0.13</version>
                        <executions>
                            <execution>
                                <phase>validate</phase>
                                <goals>
                                    <goal>check</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <excludes>
                                <exclude>**/*.json</exclude>
                                <exclude>**/*.yml</exclude>
                                <exclude>**/*.md</exclude>
                                <exclude>**/*.log</exclude>
                                <exclude>**/*.properties</exclude>
                                <exclude>.editorconfig</exclude>
                                <exclude>.sonarcloud.properties</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>compatibility-check</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.spurint.maven.plugins</groupId>
                        <artifactId>mima-maven-plugin</artifactId>
                        <version>0.8.0</version>
                        <executions>
                            <execution>
                                <id>check-abi</id>
                                <goals>
                                    <goal>check-abi</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>code-coverage</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>za.co.absa.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>${jacoco.version}</version>
                        <configuration>
                            <excludes>
                                <exclude>za/co/absa/abris/examples/**</exclude>
                            </excludes>
                        </configuration>
                        <executions>
                            <execution>
                                <id>jacoco-prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>jacoco-report</id>
                                <goals>
                                    <goal>report</goal>
                                </goals>
                                <configuration>
                                    <title>${project.name} - scala:${scala.version}</title>
                                    <doMethodFiltration>true</doMethodFiltration>
                                    <doScalaMethodFiltration>true</doScalaMethodFiltration>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
