<?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>nl.mijnoverheidzakelijk.ldv</groupId>
    <artifactId>logboekdataverwerking-wrapper</artifactId>
    <version>1.1.0</version>

    <name>Logboek Dataverwerkingen Clickhouse</name>
    <description>JVM utilities to integrate the Logboek Dataverwerkingen (LDV) standard using a Clickhouse DB by Logius.</description>
    <url>https://github.com/MinBZK/moza-logboekdataverwerking</url>

    <licenses>
        <license>
            <name>European Union Public License 1.2</name>
            <url>https://eupl.eu/1.2/en/</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <developers>
        <developer>
            <id>moza</id>
            <name>MijnOverheid Zakelijk</name>
            <email>tijmen.brink@rijksoverheid.nl</email>
            <organization>MinBZK</organization>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:https://github.com/MinBZK/moza-logboekdataverwerking.git</connection>
        <developerConnection>scm:git:ssh://git@github.com/MinBZK/moza-logboekdataverwerking.git</developerConnection>
        <url>https://github.com/MinBZK/moza-logboekdataverwerking</url>
        <tag>HEAD</tag>
    </scm>

    <properties>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- 2.3.20, not 2.4.x: CodeQL doesn't support Kotlin 2.4 yet (github/codeql#21938) -->
        <kotlin.version>2.3.21</kotlin.version>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>6.1.3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- Database drivers are <optional>: this library is compiled and tested
             against both backends, but a consuming application only runs one. Marking
             them optional keeps both off the consumer's transitive classpath, so each
             app declares just the driver for the backend it selects via
             logboekdataverwerking.dbms (clickhouse|postgresql). The backend is chosen
             at runtime, so the unused driver is never loaded. A consumer that selects a
             backend without declaring its driver fails loud at startup (see
             ConfigurationLoader.validate*Config). -->
        <dependency>
            <groupId>com.clickhouse</groupId>
            <artifactId>client-v2</artifactId>
            <version>0.10.0</version>
            <optional>true</optional>
        </dependency>
        <!-- PostgreSQL JDBC driver: alternative production-capable backend.
             Selected via logboekdataverwerking.dbms=postgresql. -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.7.13</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-api</artifactId>
            <version>1.66.0</version>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-otlp</artifactId>
            <version>1.66.0</version>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-sdk</artifactId>
            <version>1.66.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-configuration2</artifactId>
            <version>2.15.1</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.11.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.22.2</version>
        </dependency>

        <!-- Add SnakeYAML for YAML support -->
        <dependency>
            <groupId>org.yaml</groupId>
            <artifactId>snakeyaml</artifactId>
            <version>2.7</version>
        </dependency>


        <dependency>
            <groupId>jakarta.enterprise</groupId>
            <artifactId>jakarta.enterprise.cdi-api</artifactId>
            <version>5.0.0</version>
            <scope>provided</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/jakarta.ws.rs/jakarta.ws.rs-api -->
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <version>4.0.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- MicroProfile Config API -->
        <dependency>
            <groupId>org.eclipse.microprofile.config</groupId>
            <artifactId>microprofile-config-api</artifactId>
            <version>3.1.1</version>
            <scope>provided</scope>
        </dependency>

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

        <!-- Testing -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.mockk</groupId>
            <artifactId>mockk-jvm</artifactId>
            <version>1.14.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.mockk</groupId>
            <artifactId>mockk-agent</artifactId>
            <version>1.14.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.19</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.code-intelligence</groupId>
            <artifactId>jazzer-api</artifactId>
            <version>0.30.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <!-- Use Kotlin source directories instead of default Java directories -->
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <testSourceDirectory>src/test/kotlin</testSourceDirectory>
        <plugins>
            <!-- JVM flags for MockK/ByteBuddy compatibility:
                 - EnableDynamicAgentLoading: MockK uses ByteBuddy to mock final classes and
                   constructors at runtime. JDK 21+ warns about dynamic agent loading.
                   In future JDK versions, this may need to be replaced with static agent loading.
                 - Xshare:off: Disables Class Data Sharing which conflicts with ByteBuddy's
                   bootstrap classpath modifications. CDS is a startup optimization not needed for tests.
                 Build and test on JDK 21 (the project target). On a JDK newer than ByteBuddy's
                 supported max, inline mocking of java.base final classes silently fails and the mock
                 falls through to the REAL method (e.g. CompletableFuture.get() blocks forever and
                 hangs the suite); use a JDK 21 toolchain rather than -Dnet.bytebuddy.experimental. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <argLine>-XX:+EnableDynamicAgentLoading -Xshare:off</argLine>
                </configuration>
            </plugin>
            <!-- Attach sources and Javadocs as required by Maven Central -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.4.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- maven-javadoc-plugin produces nothing for Kotlin-only sources;
                 Dokka generates the javadoc jar Central requires from KDoc -->
            <plugin>
                <groupId>org.jetbrains.dokka</groupId>
                <artifactId>dokka-maven-plugin</artifactId>
                <version>2.2.0</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>javadocJar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.smallrye</groupId>
                <artifactId>jandex-maven-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>make-index</id>
                        <goals>
                            <goal>jandex</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.11.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <jvmTarget>${maven.compiler.target}</jvmTarget>
                    <compilerPlugins>
                        <plugin>all-open</plugin>
                    </compilerPlugins>
                    <pluginOptions>
                        <option>all-open:annotation=jakarta.enterprise.context.ApplicationScoped</option>
                        <option>all-open:annotation=jakarta.enterprise.context.RequestScoped</option>
                        <option>all-open:annotation=jakarta.interceptor.Interceptor</option>
                    </pluginOptions>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.jetbrains.kotlin</groupId>
                        <artifactId>kotlin-maven-allopen</artifactId>
                        <version>${kotlin.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>central</id>
            <url>https://central.sonatype.com/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

    <!-- Sign artifacts only for release builds -->
    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>3.2.8</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
