<?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>io.github.auspis</groupId>
  <artifactId>fluent-repo-4j</artifactId>
  <version>1.4.1</version>
  <packaging>jar</packaging>

  <name>fluent-repo-4j</name>
  <description>Lightweight Spring Boot Repositories - DSL for simple, type-safe and maintainable SQL</description>
  <url>https://github.com/auspis/fluent-repo-4j</url>

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

  <developers>
    <developer>
      <id>auspis</id>
      <name>Auspis</name>
    </developer>
  </developers>

  <scm>
    <connection>scm:git:git://github.com/auspis/fluent-repo-4j.git</connection>
    <developerConnection>scm:git:ssh://git@github.com:auspis/fluent-repo-4j.git</developerConnection>
    <url>https://github.com/auspis/fluent-repo-4j</url>
  </scm>

  <!-- Distribution settings for Sonatype Central Publishing Portal -->
  <distributionManagement>
    <repository>
      <id>central</id>
      <url>https://central.sonatype.com/api/v1/publisher/upload</url>
    </repository>
  </distributionManagement>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
    <maven.surefire.plugin.version>3.5.6</maven.surefire.plugin.version>
    <maven.failsafe.plugin.version>3.5.6</maven.failsafe.plugin.version>
    <maven.spotless.plugin.version>3.6.0</maven.spotless.plugin.version>
    <maven.resource.plugin.version>3.5.0</maven.resource.plugin.version>
    <maven.exec.plugin.version>3.6.3</maven.exec.plugin.version>
    <maven.sonar-scanner.plugin.version>5.7.0.6970</maven.sonar-scanner.plugin.version>
    <maven.sonatype-central-publishing.plugin.version>0.10.0</maven.sonatype-central-publishing.plugin.version>
    <maven.source.plugin.version>3.4.0</maven.source.plugin.version>
    <maven.javadoc.plugin.version>3.12.0</maven.javadoc.plugin.version>
    <maven.gpg.plugin.version>3.2.8</maven.gpg.plugin.version>
    <sonar.host.url>https://sonarcloud.io</sonar.host.url>
    <sonar.organization>auspis</sonar.organization>
    <sonar.projectKey>auspis_fluent-repo-4j</sonar.projectKey>
    <jacoco.version>0.8.15</jacoco.version>
    <argLine/>
    <central.autoPublish>false</central.autoPublish>
    <!-- Baseline for internal build; consumers bring their own Spring Boot version -->
    <spring-boot.version>3.5.15</spring-boot.version>
    <fluent-sql-4j.version>1.4.1</fluent-sql-4j.version>
    <testcontainers.version>2.0.5</testcontainers.version>
    <test.groups.slow>integration,e2e</test.groups.slow>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring-boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <!-- Spring Data Commons (Repository SPI, EntityInformation) - provided by consumer's Spring Boot -->
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-commons</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Spring JDBC (DataSourceUtils, RowMapper, SQLExceptionTranslator) - provided by consumer's Spring Boot -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- JPA annotations (@Table, @Column, @Id) - API only, exposed transitively for downstream consumers -->
    <dependency>
      <groupId>jakarta.persistence</groupId>
      <artifactId>jakarta.persistence-api</artifactId>
      <scope>compile</scope>
    </dependency>

    <!-- fluent-sql-4j DSL -->
    <dependency>
      <groupId>io.github.auspis.fluentsql4j</groupId>
      <artifactId>api</artifactId>
      <version>${fluent-sql-4j.version}</version>
    </dependency>

    <!-- Spring Boot AutoConfiguration (optional) -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-autoconfigure</artifactId>
      <optional>true</optional>
    </dependency>

    <!-- Test dependencies -->
    <dependency>
      <groupId>io.github.auspis.fluentsql4j</groupId>
      <artifactId>plugin-mysql</artifactId>
      <version>${fluent-sql-4j.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.github.auspis.fluentsql4j</groupId>
      <artifactId>plugin-postgresql</artifactId>
      <version>${fluent-sql-4j.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.github.auspis.fluentsql4j</groupId>
      <artifactId>test-support</artifactId>
      <version>${fluent-sql-4j.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers-junit-jupiter</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers-mysql</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testcontainers</groupId>
      <artifactId>testcontainers-postgresql</artifactId>
      <version>${testcontainers.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.mysql</groupId>
      <artifactId>mysql-connector-j</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.sonarsource.scanner.maven</groupId>
          <artifactId>sonar-maven-plugin</artifactId>
          <version>${maven.sonar-scanner.plugin.version}</version>
        </plugin>
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>${jacoco.version}</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>com.diffplug.spotless</groupId>
        <artifactId>spotless-maven-plugin</artifactId>
        <version>${maven.spotless.plugin.version}</version>
        <configuration>
          <java>
            <palantirJavaFormat/>
            <encoding>${project.build.sourceEncoding}</encoding>
            <importOrder>
              <order>jakarta</order>
              <order>java</order>
              <order>javax</order>
              <order>org</order>
              <order>com</order>
              <order>io</order>
            </importOrder>
            <removeUnusedImports/>
            <formatAnnotations/>
            <trimTrailingWhitespace/>
            <endWithNewline/>
          </java>
          <pom>
            <sortPom>
              <encoding>${project.build.sourceEncoding}</encoding>
              <expandEmptyElements>false</expandEmptyElements>
            </sortPom>
            <trimTrailingWhitespace/>
            <endWithNewline/>
          </pom>
          <markdown>
            <includes>
              <include>**/*.md</include>
            </includes>
            <flexmark/>
          </markdown>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>${maven.resource.plugin.version}</version>
        <inherited>false</inherited>
        <executions>
          <execution>
            <id>install-pre-commit-hook</id>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <phase>generate-resources</phase>
            <configuration>
              <outputDirectory>${basedir}/.git/hooks</outputDirectory>
              <resources>
                <resource>
                  <directory>${basedir}/data/scripts</directory>
                  <includes>
                    <include>pre-commit</include>
                  </includes>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>${maven.exec.plugin.version}</version>
        <inherited>false</inherited>
        <executions>
          <execution>
            <id>chmod-pre-commit-hook</id>
            <goals>
              <goal>exec</goal>
            </goals>
            <phase>process-resources</phase>
            <configuration>
              <executable>chmod</executable>
              <workingDirectory>${basedir}</workingDirectory>
              <arguments>
                <argument>+x</argument>
                <argument>.git/hooks/pre-commit</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${maven.failsafe.plugin.version}</version>
        <configuration>
          <argLine>${jacocoArgLine} ${argLine}</argLine>
          <includes>
            <include>**/*Test.java</include>
            <include>**/*IT.java</include>
            <include>**/*E2ETest.java</include>
          </includes>
          <groups>${test.groups.slow}</groups>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${maven.surefire.plugin.version}</version>
        <configuration>
          <excludedGroups>${test.groups.slow}</excludedGroups>
          <argLine>${jacocoArgLine} ${argLine}</argLine>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>${jacoco.version}</version>
        <executions>
          <execution>
            <id>prepare-agent</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
            <configuration>
              <propertyName>jacocoArgLine</propertyName>
              <destFile>${project.build.directory}/jacoco.exec</destFile>
              <append>true</append>
            </configuration>
          </execution>
          <execution>
            <id>report</id>
            <goals>
              <goal>report</goal>
            </goals>
            <phase>verify</phase>
            <configuration>
              <outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <!--
    Profiles to support selective test execution via -Dgroups=<value>.
    Problem: Failsafe's <groups>${test.groups.slow}</groups> is resolved from the POM
    property expression before Maven's user-property injection runs, so passing
    -Dgroups=integration directly does NOT override the failsafe groups configuration.
    Solution: property-activated profiles explicitly set <groups> for failsafe, making
    -Dgroups=integration and -Dgroups=e2e work as expected.
  -->
  <profiles>
    <profile>
      <id>filter-integration</id>
      <activation>
        <property>
          <name>groups</name>
          <value>integration</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <groups>integration</groups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>filter-e2e</id>
      <activation>
        <property>
          <name>groups</name>
          <value>e2e</value>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <configuration>
              <groups>e2e</groups>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>release</id>
      <activation>
        <property>
          <name>performRelease</name>
          <value>true</value>
        </property>
      </activation>
      <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>
            <configuration>
              <doclint>none</doclint>
              <failOnError>false</failOnError>
              <excludePackageNames>*.helper</excludePackageNames>
            </configuration>
            <executions>
              <execution>
                <id>attach-javadocs</id>
                <goals>
                  <goal>jar</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>${maven.gpg.plugin.version}</version>
            <executions>
              <execution>
                <id>sign-artifacts</id>
                <goals>
                  <goal>sign</goal>
                </goals>
                <phase>verify</phase>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.sonatype.central</groupId>
            <artifactId>central-publishing-maven-plugin</artifactId>
            <version>${maven.sonatype-central-publishing.plugin.version}</version>
            <extensions>true</extensions>
            <configuration>
              <publishingServerId>central</publishingServerId>
              <autoPublish>${central.autoPublish}</autoPublish>
              <waitUntil>validated</waitUntil>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
