<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>dev.hermannm</groupId>
  <artifactId>devlog-kotlin</artifactId>
  <version>0.1.0</version>
  <packaging>jar</packaging>

  <name>devlog-kotlin</name>
  <description>
    Logging library for Kotlin JVM, that thinly wraps SLF4J and Logback to provide a more ergonomic API.
  </description>
  <url>https://hermannm.dev/devlog</url>

  <licenses>
    <license>
      <name>MIT</name>
      <url>https://github.com/hermannm/devlog-kotlin/blob/main/LICENSE</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <developers>
    <developer>
      <id>hermannm</id>
      <name>Hermann Mørkrid</name>
      <url>https://hermannm.dev</url>
      <email>hermann.morkrid@gmail.com</email>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:https://github.com/hermannm/devlog-kotlin.git</connection>
    <developerConnection>scm:git:https://github.com/hermannm/devlog-kotlin.git</developerConnection>
    <url>https://github.com/hermannm/devlog-kotlin</url>
  </scm>

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

    <kotlin.version>2.0.21</kotlin.version>
    <java.version>17</java.version>
    <kotlin.compiler.jvmTarget>${java.version}</kotlin.compiler.jvmTarget>
    <kotlin.compiler.incremental>true</kotlin.compiler.incremental>

    <!-- Logging -->
    <logback.version>1.5.12</logback.version>
    <logstash-logback-encoder.version>8.0</logstash-logback-encoder.version>
    <!-- Use same SLF4J version as Logback (Logback is the more important dependency here, so we want to match it) -->
    <slf4j.version>2.0.15</slf4j.version>

    <!-- Serialization -->
    <kotlinx-serialization.version>1.7.3</kotlinx-serialization.version>

    <!-- Testing -->
    <junit.version>5.11.3</junit.version>
    <kotest.version>5.9.1</kotest.version>

    <!-- Maven plugins -->
    <spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
    <ktfmt.version>0.43</ktfmt.version>
    <maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version>
    <maven-enforcer.version>3.4.1</maven-enforcer.version>
    <maven-source-plugin.version>3.3.1</maven-source-plugin.version>
    <dokka-maven-plugin.version>1.9.20</dokka-maven-plugin.version>
    <maven-gpg-plugin.version>3.2.7</maven-gpg-plugin.version>
    <central-publishing-maven-plugin.version>0.6.0</central-publishing-maven-plugin.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-bom</artifactId>
        <version>${kotlin.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <!-- Kotlin -->
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib</artifactId>
      <version>${kotlin.version}</version>
    </dependency>

    <!-- Logging -->
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback.version}</version>
    </dependency>
    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>${logstash-logback-encoder.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>

    <!-- Serialization -->
    <dependency>
      <groupId>org.jetbrains.kotlinx</groupId>
      <artifactId>kotlinx-serialization-json</artifactId>
      <version>${kotlinx-serialization.version}</version>
    </dependency>

    <!-- Testing -->
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.kotest</groupId>
      <artifactId>kotest-assertions-core-jvm</artifactId>
      <version>${kotest.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

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

    <plugins>
      <!-- Kotlin compilation and kotlinx.serialization codegen -->
      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>${kotlin.version}</version>
        <configuration>
          <jvmTarget>${java.version}</jvmTarget>
          <compilerPlugins>
            <plugin>kotlinx-serialization</plugin>
          </compilerPlugins>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-serialization</artifactId>
            <version>${kotlin.version}</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <phase>compile</phase>
          </execution>
          <execution>
            <id>test-compile</id>
            <goals>
              <goal>test-compile</goal>
            </goals>
            <phase>test-compile</phase>
          </execution>
        </executions>
      </plugin>

      <!-- Testing -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven-surefire-plugin.version}</version>
      </plugin>

      <!-- Formatting with ktfmt -->
      <plugin>
        <groupId>com.diffplug.spotless</groupId>
        <artifactId>spotless-maven-plugin</artifactId>
        <version>${spotless-maven-plugin.version}</version>
        <configuration>
          <kotlin>
            <toggleOffOn/>
            <ktfmt>
              <version>${ktfmt.version}</version>
              <style>DEFAULT</style>
            </ktfmt>
          </kotlin>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>check</goal>
            </goals>
            <phase>validate</phase>
          </execution>
        </executions>
      </plugin>

      <!-- Plugin for enforcing proper dependency management -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>${maven-enforcer.version}</version>
        <executions>
          <execution>
            <id>enforce</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <banDuplicatePomDependencyVersions/>
                <dependencyConvergence/>
                <requireUpperBoundDeps/>
                <banDynamicVersions/>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Generates source file JARs, required for publishing to Maven Central -->
      <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>

      <!-- Generates Javadoc JAR, required for publishing to Maven Central -->
      <plugin>
        <groupId>org.jetbrains.dokka</groupId>
        <artifactId>dokka-maven-plugin</artifactId>
        <version>${dokka-maven-plugin.version}</version>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>javadocJar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Signs built artifacts with GPG, required for publishing to Maven Central -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-gpg-plugin</artifactId>
        <version>${maven-gpg-plugin.version}</version>
        <executions>
          <execution>
            <id>sign-artifacts</id>
            <phase>verify</phase>
            <goals>
              <goal>sign</goal>
            </goals>
            <configuration>
              <bestPractices>true</bestPractices>
              <keyname>${gpg.keyname}</keyname>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Publishes to Maven Central -->
      <plugin>
        <groupId>org.sonatype.central</groupId>
        <artifactId>central-publishing-maven-plugin</artifactId>
        <version>${central-publishing-maven-plugin.version}</version>
        <extensions>true</extensions>
        <configuration>
          <publishingServerId>central</publishingServerId>
          <deploymentName>Release ${version}</deploymentName>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
