plugins {
    val kotlinVersion: String by System.getProperties()
    val joobyVersion: String by System.getProperties()
    kotlin("jvm") version kotlinVersion
{{#if kapt}}
    kotlin("kapt") version kotlinVersion
{{/if}}
{{#if openapi}}
    id("io.jooby.openAPI") version joobyVersion
{{/if}}
    id("io.jooby.run") version joobyVersion
    id("io.spring.dependency-management") version "1.1.0"
    id("com.google.osdetector") version "1.7.3"
    id("com.gradleup.shadow") version "8.3.7"
}

repositories {
    mavenLocal()
    mavenCentral()
}

group "{{groupId}}"
version "{{version}}"

val kotlinVersion: String by System.getProperties()
val joobyVersion: String by System.getProperties()

val mainAppClassName = "{{package}}.AppKt"

dependencyManagement {
    imports {
        mavenBom("io.jooby:jooby-bom:$joobyVersion")
    }
}

dependencies {
{{#if kapt}}
    kapt("io.jooby:jooby-apt")
{{/if}}
{{#each dependencies}}
    implementation ("{{this}}")
{{/each}}

    testImplementation("org.jetbrains.kotlin:kotlin-test")
    testImplementation("io.jooby:jooby-test")
    testImplementation("com.squareup.okhttp3:okhttp-jvm:5.1.0")
}


kotlin {
    jvmToolchain(21)

    compilerOptions {
        javaParameters = true
    }
}

tasks {
{{#if kapt}}
    kapt {
      arguments {
        arg("jooby.incremental", "true")
        arg("jooby.debug", "false")
      }
    }
{{/if}}
    test {
        useJUnitPlatform()
    }
    shadowJar {
        mergeServiceFiles()
    }

    joobyRun {
        mainClass = mainAppClassName
        restartExtensions = listOf("conf", "properties", "class")
        compileExtensions = listOf("java", "kt")
        port = 8080
{{#if openapi}}
        dependsOn("openAPI")
{{/if}}
    }
{{#if openapi}}
    openAPI {
      mainClass = mainAppClassName
    }

    jar {
      dependsOn("openAPI")
    }
{{/if}}
}

