import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

tasks.wrapper {
    distributionType = Wrapper.DistributionType.ALL
}

plugins {
    kotlin("jvm") version "2.0.21"
    application
    id("nu.studer.rocker") version "3.0.4"
    id("com.gradleup.shadow") version "8.3.4"
}

group = "io.vertx"
version = "4.3.8" // 4.5.10 is available, but this is not updated to be kept consistent with the "vert-web" portion

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
    implementation(platform("io.vertx:vertx-stack-depchain:$version"))
    implementation("io.vertx:vertx-core")
    implementation("com.fasterxml.jackson.module:jackson-module-blackbird:2.14.2") // 2.18.1 is available, but this is not updated to be kept consistent with the "vert-web" portion
    implementation("io.vertx:vertx-web")
    implementation("io.vertx:vertx-pg-client")
    implementation("io.vertx:vertx-web-templ-rocker")
    runtimeOnly("io.netty", "netty-transport-native-epoll", classifier = "linux-x86_64")
    // not used to make the project consistent with the "vert-web" portion
    /*
    runtimeOnly("io.vertx:vertx-io_uring-incubator")
    runtimeOnly("io.netty.incubator:netty-incubator-transport-native-io_uring:0.0.25.Final:linux-x86_64")
    */
    implementation("io.vertx:vertx-lang-kotlin")
    implementation("io.vertx:vertx-lang-kotlin-coroutines")
}

rocker {
    configurations {
        create("main") {
            templateDir.set(file("src/main/resources"))
            optimize.set(true)
            javaVersion.set("17") // kept consistent with the "vert-web" portion
        }
    }
}

kotlin.jvmToolchain(17) // kept consistent with the "vert-web" portion


// content below copied from the project generated by the app generator

val mainVerticleName = "io.vertx.benchmark.App"
val launcherClassName = "io.vertx.core.Launcher"
application {
    mainClass.set(launcherClassName)
}

tasks.withType<ShadowJar> {
    archiveClassifier.set("fat")
    manifest {
        attributes(mapOf("Main-Verticle" to mainVerticleName))
    }
    mergeServiceFiles()
}

val watchForChange = "src/**/*"
val doOnChange = "${projectDir}/gradlew classes"
tasks.withType<JavaExec> {
    args = listOf(
        "run",
        mainVerticleName,
        "--redeploy=$watchForChange",
        "--launcher-class=$launcherClassName",
        "--on-redeploy=$doOnChange"
    )
}
