<?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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <artifactId>{{artifactId}}</artifactId>
  <groupId>{{groupId}}</groupId>
  <version>{{version}}</version>

  <name>{{artifactId}}</name>

  <properties>
    <!-- Startup class -->
    <application.class>{{package}}.App{{#if kotlin}}Kt{{/if}}</application.class>

    <jooby.version>{{joobyVersion}}</jooby.version>

    {{#if kotlin}}
    <kotlin.version>{{kotlinVersion}}</kotlin.version>
    <kotlin.compiler.incremental>true</kotlin.compiler.incremental>
    {{/if}}
    <maven.compiler.source>21</maven.compiler.source>
    <maven.compiler.target>21</maven.compiler.target>
    <maven.compiler.parameters>true</maven.compiler.parameters>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
  {{#each dependencies}}
    <dependency>
      <groupId>{{groupId}}</groupId>
      <artifactId>{{artifactId}}</artifactId>
      {{~#if version~}}<version>{{version}}</version>{{~/if}}
    </dependency>
  {{/each}}
    <!-- Tests -->
  {{#each testDependencies}}
    <dependency>
      <groupId>{{groupId}}</groupId>
      <artifactId>{{artifactId}}</artifactId>
      {{#if version}}
      <version>{{version}}</version>
      <scope>test</scope>
      {{else}}
      <scope>test</scope>
      {{/if}}
    </dependency>
  {{/each}}
  </dependencies>

  <build>
  {{#if kotlin}}
    <sourceDirectory>${project.basedir}${file.separator}src${file.separator}main${file.separator}kotlin</sourceDirectory>
    <testSourceDirectory>${project.basedir}${file.separator}src${file.separator}test${file.separator}kotlin</testSourceDirectory>
  {{/if}}
    <resources>
      <resource>
        <directory>conf</directory>
      </resource>
      <resource>
        <directory>src${file.separator}main${file.separator}resources</directory>
      </resource>
    </resources>
    <plugins>
    {{#if kotlin}}
      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>${kotlin.version}</version>
        <configuration>
          <args>
            <arg>-java-parameters</arg>
          </args>
          <jvmTarget>${maven.compiler.target}</jvmTarget>
        </configuration>
        <executions>
        {{#if kapt}}
          <execution>
            <id>kapt</id>
            <goals>
              <goal>kapt</goal>
            </goals>
            <configuration>
              <sourceDirs>
                <sourceDir>src/main/kotlin</sourceDir>
              </sourceDirs>
              <annotationProcessorPaths>
                <annotationProcessorPath>
                  <groupId>io.jooby</groupId>
                  <artifactId>jooby-apt</artifactId>
                  <version>${jooby.version}</version>
                </annotationProcessorPath>
              </annotationProcessorPaths>
              <annotationProcessorArgs>
                <annotationProcessorArg>
                  jooby.debug=false
                </annotationProcessorArg>
              </annotationProcessorArgs>
            </configuration>
          </execution>
        {{/if}}
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
          <execution>
            <id>test-compile</id>
            <goals>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    {{else}}
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>{{mavenCompilerPluginVersion}}</version>
      {{#if apt}}
        <configuration>
          <annotationProcessorPaths>
            <!-- if using lombok, it must be placed before the jooby-apt -->
            <!-- if using avaje-inject, it must be placed after lombok, but before the jooby-apt -->
            <path>
              <groupId>io.jooby</groupId>
              <artifactId>jooby-apt</artifactId>
              <version>${jooby.version}</version>
            </path>
          </annotationProcessorPaths>
          <compilerArgs>
            <compilerArg>
              -Ajooby.debug=false
            </compilerArg>
          </compilerArgs>
        </configuration>
      {{/if}}
      </plugin>
    {{/if}}
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>{{mavenSurefirePluginVersion}}</version>
      </plugin>
      <!-- jooby:run -->
      <plugin>
        <groupId>io.jooby</groupId>
        <artifactId>jooby-maven-plugin</artifactId>
        <version>${jooby.version}</version>
        {{#if openapi}}
        <executions>
          <execution>
            <goals>
              <goal>openapi</goal>
            </goals>
            <configuration>
            </configuration>
          </execution>
        </executions>
        {{/if}}
        {{#if kotlin}}
        <dependencies>
          <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-reflect</artifactId>
            <version>${kotlin.version}</version>
          </dependency>
        </dependencies>
        {{/if}}
      </plugin>
      {{#if stork}}
      <plugin>
        <groupId>io.repaint.maven</groupId>
        <artifactId>tiles-maven-plugin</artifactId>
        <version>{{mavenTilesPluginVersion}}</version>
        <extensions>true</extensions>
        <configuration>
          <tiles>
            <tile>io.jooby:jooby-stork:${jooby.version}</tile>
          </tiles>
        </configuration>
      </plugin>
      {{else}}
      <!-- Build uber jar -->
      <plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <version>{{mavenShadePluginVersion}}</version>
        <executions>
          <execution>
            <id>uber-jar</id>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <transformers>
                <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                <transformer
                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>${application.class}</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
      {{/if}}
    </plugins>
  </build>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.jooby</groupId>
        <artifactId>jooby-bom</artifactId>
        <version>${jooby.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>
