<?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>

  <parent>
    <groupId>de.loosetie.crudular</groupId>
    <artifactId>lt-crudular-parent</artifactId>
    <version>2.1.2</version>
    <relativePath>../_parent/pom.xml</relativePath>
  </parent>

  <artifactId>lt-crudular-test</artifactId>

  <name>LT :: CRUDular :: Test</name>
  <!--suppress MavenRedundantGroupId https://codeberg.org/forgejo/forgejo/pulls/6329 waiting for release 10 -->
  <groupId>de.loosetie.crudular</groupId>

  <dependencies>
    <dependency>
      <groupId>de.loosetie.crudular</groupId>
      <artifactId>lt-crudular-base</artifactId>
    </dependency>

    <!-- Generated jOOQ schema (src/main/java) is the shared test schema consumed by the jooq repo modules. -->
    <dependency>
      <groupId>org.jooq</groupId>
      <artifactId>jooq</artifactId>
    </dependency>

    <dependency>
      <groupId>jakarta.validation</groupId>
      <artifactId>jakarta.validation-api</artifactId>
    </dependency>

    <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-database-postgresql</artifactId>
    </dependency>
    <dependency>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-test</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
    </dependency>

  </dependencies>

  <build>
    <plugins>
      <!--
        Regenerating the checked-in jOOQ schema (src/main/java). Neither plugin is bound to a lifecycle phase,
        so a normal build never touches the DB; regenerate manually against a running Postgres with:
          mvn -pl :lt-crudular-test flyway:clean flyway:migrate jooq-codegen:generate
      -->
      <plugin>
        <groupId>org.flywaydb</groupId>
        <artifactId>flyway-maven-plugin</artifactId>
        <version>12.1.0</version>
        <configuration>
          <url>jdbc:postgresql://localhost:5432/crudular</url>
          <user>crudular</user>
          <password>crudular</password>
          <cleanDisabled>false</cleanDisabled>
          <locations>
            <location>filesystem:${project.basedir}/src/main/resources/db/default/migration</location>
          </locations>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-database-postgresql</artifactId>
            <version>12.1.0</version>
          </dependency>
          <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${version.postgresql}</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <groupId>org.jooq</groupId>
        <artifactId>jooq-codegen-maven</artifactId>
        <configuration>
          <configurationFile>${project.basedir}/jooq-codegen-config.xml</configurationFile>
          <jdbc>
            <driver>org.postgresql.Driver</driver>
            <url>jdbc:postgresql://localhost:5432/crudular</url>
            <user>crudular</user>
            <password>crudular</password>
          </jdbc>
          <generator>
            <target>
              <directory>src/main/java</directory>
              <packageName>de.loosetie.crudular.repo.jooq.generated</packageName>
            </target>
          </generator>
        </configuration>
      </plugin>

      <!--
        The generated jOOQ schema lives in src/main/java. The kotlin parent points the build's
        sourceDirectory at src/main/kotlin, so Java main sources need to be compiled explicitly:
        the kotlin plugin registers src/main/java, then maven-compiler compiles it against the
        already-compiled kotlin classes.
      -->
      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <sourceDirs>
                <sourceDir>src/main/kotlin</sourceDir>
                <sourceDir>src/main/java</sourceDir>
              </sourceDirs>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <executions>
          <execution>
            <!-- Replacing default-compile as it is treated specially by maven -->
            <id>default-compile</id>
            <phase>none</phase>
          </execution>
          <execution>
            <id>java-compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <compileSourceRoots>
                <compileSourceRoot>${project.basedir}/src/main/java</compileSourceRoot>
              </compileSourceRoots>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
