<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>

  <!-- Shared parent for all Qanary modules: inherits Spring Boot's dependency &
       plugin management, and adds Qanary-wide properties, dependencyManagement
       (pinned versions, task 2.1) and pluginManagement (publishing/signing/
       aspectj config, task 2.2). -->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>4.1.0</version>
    <relativePath/>
  </parent>

  <groupId>eu.wdaqua.qanary</groupId>
  <artifactId>mvn.reactor</artifactId>
  <!-- Release version (not SNAPSHOT): this parent is published to Maven Central
       so the released modules can resolve it as their parent. -->
  <version>5.0.2</version>
  <packaging>pom</packaging>

  <!-- Metadata required by Maven Central (the released modules use this as their
       parent, so it must itself be published with complete metadata). -->
  <name>Qanary reactor (parent POM)</name>
  <description>Shared parent POM and dependency/plugin management for the Qanary
    question answering framework modules.</description>
  <url>https://github.com/WDAqua/Qanary</url>
  <licenses>
    <license>
      <name>The Apache License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
  </licenses>
  <developers>
    <developer>
      <name>Andreas Both</name>
      <email>andreas.both@htwk-leipzig.de</email>
      <organization>WDAqua</organization>
      <organizationUrl>http://wdaqua.eu/</organizationUrl>
    </developer>
  </developers>
  <scm>
    <connection>scm:git:git://github.com/WDAqua/Qanary.git</connection>
    <developerConnection>scm:git:ssh://github.com/WDAqua/Qanary.git</developerConnection>
    <url>https://github.com/WDAqua/Qanary</url>
  </scm>

  <modules>
    <module>qanary_component-archetype</module>
    <module>qanary_commons</module>
    <module>qanary_pipeline-template</module>
    <module>qanary_component-template</module>
    <module>qanary_component-parent</module>
    <module>qald-evaluator</module>
  </modules>

  <properties>
    <java.version>21</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- Qanary artifact versions (pinned; task 2.1) -->
    <qanary.version>5.0.2</qanary.version>
    <qanary.components.version>5.0.2</qanary.components.version>

    <!-- shared library versions -->
    <jena.version>5.3.0</jena.version>
    <spring-boot-admin.version>4.1.2</spring-boot-admin.version>
    <springdoc.version>3.0.3</springdoc.version>
    <stardog.version>8.2.2</stardog.version>
    <virtuoso-jena.version>1.44</virtuoso-jena.version>
    <virtuoso-jdbc.version>3.123</virtuoso-jdbc.version>
    <commons-cli.version>1.11.0</commons-cli.version>
    <commons-configuration2.version>2.15.1</commons-configuration2.version>
    <!-- Only commons-cli and commons-configuration2 are pinned here; the Spring Boot 4 BOM does
         not manage them. The commons-lang3, gson and jakarta-xml-bind overrides were dropped:
         Boot 4.0.5 already manages commons-lang3 3.19.0 (satisfies commons-configuration2 2.15.x,
         which needs >= 3.18.0), gson 2.13.2 and jakarta.xml.bind-api 4.0.4 — exactly the versions
         we require — so those dependencies inherit their versions from the Boot BOM. -->

    <!-- build tooling versions -->
    <aspectj-maven-plugin.version>1.14.1</aspectj-maven-plugin.version>
    <aspectjtools.version>1.9.25.1</aspectjtools.version>
    <maven-release-plugin.version>3.3.1</maven-release-plugin.version>
    <central-publishing-plugin.version>0.12.0</central-publishing-plugin.version>
    <maven-gpg-plugin.version>3.2.8</maven-gpg-plugin.version>
    <!-- GPG signing (sign-artifacts execution) is bound to the verify phase, so it
         would fire on every `mvn install` and fail in CI/local builds that have no
         signing key. Default it OFF; the release workflow (maven.yml) re-enables it
         with -Dgpg.skip=false alongside the key from secrets. -->
    <gpg.skip>true</gpg.skip>
    <jacoco-maven-plugin.version>0.8.15</jacoco-maven-plugin.version>
    <spotbugs-maven-plugin.version>4.10.3.0</spotbugs-maven-plugin.version>
    <findsecbugs-plugin.version>1.14.0</findsecbugs-plugin.version>
    <pitest-maven.version>1.25.7</pitest-maven.version>
    <pitest-junit5-plugin.version>1.2.3</pitest-junit5-plugin.version>
    <testcontainers.version>1.21.4</testcontainers.version>
    <maven-enforcer-plugin.version>3.6.3</maven-enforcer-plugin.version>
    <spotless-maven-plugin.version>3.8.0</spotless-maven-plugin.version>

    <!-- Static analysis (SpotBugs, bytecode-based so it works alongside the
         AspectJ weaving). Report-only by default; enable enforcement in CI with
         -Dspotbugs.failOnError=true once the existing findings are triaged. -->
    <spotbugs.failOnError>false</spotbugs.failOnError>

    <!-- Test-coverage gate (JaCoCo). Per-class minimum line coverage enforced by
         the "jacoco-check" execution; raise this over time. Classes that can only
         be exercised by integration infrastructure (full Spring context, live
         triplestore, Spring Boot bootstrap) are excluded via jacoco.excludes. -->
    <jacoco.minimum.class.line.coverage>0.80</jacoco.minimum.class.line.coverage>
    <!-- Coverage gate is reporting-only by default; CI sets this to true. -->
    <jacoco.haltOnFailure>false</jacoco.haltOnFailure>
  </properties>

  <dependencyManagement>
    <dependencies>
      <!-- internal Qanary artifacts -->
      <dependency>
        <groupId>eu.wdaqua.qanary</groupId>
        <artifactId>qa.commons</artifactId>
        <version>${qanary.version}</version>
      </dependency>
      <dependency>
        <groupId>eu.wdaqua.qanary</groupId>
        <artifactId>qa.component</artifactId>
        <version>${qanary.components.version}</version>
      </dependency>

      <!-- Apache Jena -->
      <dependency>
        <groupId>org.apache.jena</groupId>
        <artifactId>jena-arq</artifactId>
        <version>${jena.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.jena</groupId>
        <artifactId>jena-core</artifactId>
        <version>${jena.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.jena</groupId>
        <artifactId>jena-rdfconnection</artifactId>
        <version>${jena.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.jena</groupId>
        <artifactId>apache-jena-libs</artifactId>
        <type>pom</type>
        <version>${jena.version}</version>
      </dependency>

      <!-- triplestore clients -->
      <dependency>
        <groupId>com.complexible.stardog</groupId>
        <artifactId>client-http</artifactId>
        <version>${stardog.version}</version>
      </dependency>
      <dependency>
        <groupId>com.complexible.stardog.jena</groupId>
        <artifactId>stardog-jena</artifactId>
        <version>${stardog.version}</version>
      </dependency>
      <dependency>
        <groupId>com.openlinksw</groupId>
        <artifactId>virt_jena_v5_3</artifactId>
        <version>${virtuoso-jena.version}</version>
      </dependency>
      <dependency>
        <groupId>com.openlinksw</groupId>
        <artifactId>virtjdbc4_3</artifactId>
        <version>${virtuoso-jdbc.version}</version>
      </dependency>

      <!-- misc -->
      <dependency>
        <groupId>commons-cli</groupId>
        <artifactId>commons-cli</artifactId>
        <version>${commons-cli.version}</version>
      </dependency>
      <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-configuration2</artifactId>
        <version>${commons-configuration2.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>${maven-release-plugin.version}</version>
          <configuration>
            <tagNameFormat>@{project.artifactId}-@{project.version}</tagNameFormat>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.sonatype.central</groupId>
          <artifactId>central-publishing-maven-plugin</artifactId>
          <version>${central-publishing-plugin.version}</version>
          <extensions>true</extensions>
          <configuration>
            <publishingServerId>central</publishingServerId>
            <autoPublish>true</autoPublish>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-gpg-plugin</artifactId>
          <version>${maven-gpg-plugin.version}</version>
          <configuration>
            <gpgArguments>
              <arg>--pinentry-mode</arg>
              <arg>loopback</arg>
            </gpgArguments>
          </configuration>
          <executions>
            <execution>
              <id>sign-artifacts</id>
              <phase>verify</phase>
              <goals>
                <goal>sign</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <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>
          <executions>
            <execution>
              <id>attach-javadocs</id>
              <goals>
                <goal>jar</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>dev.aspectj</groupId>
          <artifactId>aspectj-maven-plugin</artifactId>
          <version>${aspectj-maven-plugin.version}</version>
          <dependencies>
            <dependency>
              <groupId>org.aspectj</groupId>
              <artifactId>aspectjtools</artifactId>
              <version>${aspectjtools.version}</version>
            </dependency>
          </dependencies>
          <configuration>
            <complianceLevel>${java.version}</complianceLevel>
            <additionalCompilerArgs>
              <arg>-parameters</arg>
            </additionalCompilerArgs>
            <source>${java.version}</source>
            <target>${java.version}</target>
            <showWeaveInfo>false</showWeaveInfo>
            <verbose>true</verbose>
            <Xlint>ignore</Xlint>
            <encoding>UTF-8</encoding>
          </configuration>
          <executions>
            <execution>
              <goals>
                <!-- Only weave MAIN classes. The test-compile weave was removed:
                     re-weaving the already-woven qa.commons dependency
                     (weaveDependencies) during test-compile triggers AspectJ's
                     non-deterministic "key not found in wovenClassFile" abort,
                     which made CI flaky (~50%). Test sources are still compiled by
                     maven-compiler-plugin's default-testCompile (javac); the aspects
                     advise framework MAIN methods, which stay woven, so runtime and
                     test behaviour are unchanged. -->
                <goal>compile</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        <!-- Test-coverage measurement and per-class gate (added: task "test
             coverage"). prepare-agent instruments tests on-the-fly (independent
             of AspectJ compile-time weaving); report writes target/site/jacoco;
             jacoco-check enforces the per-class line-coverage minimum. -->
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>${jacoco-maven-plugin.version}</version>
          <configuration>
            <excludes>
              <!-- Spring Boot bootstrap / @SpringBootApplication entry points
                   whose sole purpose is launching the Spring context (main()),
                   which cannot be meaningfully unit-tested. -->
              <exclude>**/*Application.class</exclude>
              <exclude>**/QanaryService.class</exclude>
            </excludes>
          </configuration>
          <executions>
            <execution>
              <id>jacoco-prepare-agent</id>
              <goals>
                <goal>prepare-agent</goal>
              </goals>
            </execution>
            <execution>
              <id>jacoco-report</id>
              <phase>test</phase>
              <goals>
                <goal>report</goal>
              </goals>
            </execution>
            <execution>
              <id>jacoco-check</id>
              <phase>test</phase>
              <goals>
                <goal>check</goal>
              </goals>
              <configuration>
                <!-- Do not fail the build by default; CI opts in with
                     -Djacoco.haltOnFailure=true. Lets coverage be reported even
                     while individual classes are still being brought up to par. -->
                <haltOnFailure>${jacoco.haltOnFailure}</haltOnFailure>
                <rules>
                  <rule>
                    <element>CLASS</element>
                    <limits>
                      <limit>
                        <counter>LINE</counter>
                        <value>COVEREDRATIO</value>
                        <minimum>${jacoco.minimum.class.line.coverage}</minimum>
                      </limit>
                    </limits>
                  </rule>
                </rules>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <!-- Static analysis (added: quality task #1). SpotBugs works on the
             compiled bytecode, so it is unaffected by the AspectJ weaving. The
             FindSecBugs plugin adds security detectors. Report-only by default
             (spotbugs.failOnError=false); invoke via `mvn spotbugs:check` (gate)
             or `mvn spotbugs:spotbugs` (report -> target/spotbugsXml.xml). -->
        <plugin>
          <groupId>com.github.spotbugs</groupId>
          <artifactId>spotbugs-maven-plugin</artifactId>
          <version>${spotbugs-maven-plugin.version}</version>
          <configuration>
            <effort>Max</effort>
            <threshold>Medium</threshold>
            <failOnError>${spotbugs.failOnError}</failOnError>
            <includeTests>false</includeTests>
            <plugins>
              <plugin>
                <groupId>com.h3xstream.findsecbugs</groupId>
                <artifactId>findsecbugs-plugin</artifactId>
                <version>${findsecbugs-plugin.version}</version>
              </plugin>
            </plugins>
          </configuration>
        </plugin>
        <!-- Mutation testing (added: quality task #1). On-demand only (slow); not
             bound to a lifecycle phase. Run per module, e.g.:
               mvn -pl qanary_commons org.pitest:pitest-maven:mutationCoverage
             Reports -> target/pit-reports. Verifies tests actually detect
             injected faults, not just execute the lines. -->
        <plugin>
          <groupId>org.pitest</groupId>
          <artifactId>pitest-maven</artifactId>
          <version>${pitest-maven.version}</version>
          <dependencies>
            <dependency>
              <groupId>org.pitest</groupId>
              <artifactId>pitest-junit5-plugin</artifactId>
              <version>${pitest-junit5-plugin.version}</version>
            </dependency>
          </dependencies>
          <configuration>
            <targetClasses>
              <param>eu.wdaqua.qanary.*</param>
            </targetClasses>
            <outputFormats>
              <param>XML</param>
              <param>HTML</param>
            </outputFormats>
            <timestampedReports>false</timestampedReports>
            <failWhenNoMutations>false</failWhenNoMutations>
          </configuration>
        </plugin>
        <!-- Build environment guard (quality task C7): require JDK 21+ and a
             recent Maven, so a build on JDK 17 fails early and clearly instead of
             producing confusing AspectJ/compile errors. -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-enforcer-plugin</artifactId>
          <version>${maven-enforcer-plugin.version}</version>
          <executions>
            <execution>
              <id>enforce-build-environment</id>
              <goals>
                <goal>enforce</goal>
              </goals>
              <configuration>
                <rules>
                  <requireJavaVersion>
                    <version>[21,)</version>
                    <message>This project requires JDK 21 or newer (the modules compile to Java 21).</message>
                  </requireJavaVersion>
                  <requireMavenVersion>
                    <version>[3.6.3,)</version>
                  </requireMavenVersion>
                </rules>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <!-- Formatting (quality task C8). Lightweight, engine-free rules (import
             order, trailing whitespace, final newline) so there is no mass
             re-indentation. Run `mvn com.diffplug.spotless:spotless-maven-plugin:check`
             to report drift (CI does this, non-blocking) or `:apply` to adopt it. -->
        <plugin>
          <groupId>com.diffplug.spotless</groupId>
          <artifactId>spotless-maven-plugin</artifactId>
          <version>${spotless-maven-plugin.version}</version>
          <configuration>
            <java>
              <includes>
                <include>src/main/java/**/*.java</include>
                <include>src/test/java/**/*.java</include>
              </includes>
              <importOrder/>
              <trimTrailingWhitespace/>
              <endWithNewline/>
            </java>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>

    <!-- The parent itself is signed & published to Maven Central (release
         process) so released modules can resolve it. Skipped on local installs
         via -Dgpg.skip / non-deploy phases. -->
    <plugins>
      <plugin>
        <groupId>org.sonatype.central</groupId>
        <artifactId>central-publishing-maven-plugin</artifactId>
        <extensions>true</extensions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-gpg-plugin</artifactId>
      </plugin>
      <!-- Activate JaCoCo for every module (config inherited from
           pluginManagement above). Generates coverage and enforces the gate. -->
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
      </plugin>
      <!-- SpotBugs available for every module (config from pluginManagement).
           Not bound to a lifecycle phase, so normal builds are unaffected; run
           explicitly with `mvn spotbugs:check` (CI static-analysis step). -->
      <plugin>
        <groupId>com.github.spotbugs</groupId>
        <artifactId>spotbugs-maven-plugin</artifactId>
      </plugin>
      <!-- Enforce the build environment (JDK 21+, Maven) for every module. -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
      </plugin>
      <!-- Spotless present (config + version from pluginManagement) so the
           check/apply goals work; not phase-bound, so normal builds are unaffected. -->
      <plugin>
        <groupId>com.diffplug.spotless</groupId>
        <artifactId>spotless-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>
