import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val springVersion = "3.2.0"

plugins {
    id("org.springframework.boot") version "3.2.0"
    id("io.spring.dependency-management") version "1.1.4"
    id("org.jetbrains.kotlin.plugin.allopen") version "1.9.21"
//    id("io.gitlab.arturbosch.detekt").version("1.23.3")
    kotlin("jvm") version "1.9.21"
    kotlin("plugin.spring") version "1.9.21"
    kotlin("plugin.jpa") version "1.9.21"
    kotlin("plugin.serialization") version "1.9.21"
}

allOpen {
    annotation("javax.persistence.Entity")
    annotation("javax.persistence.Embeddable")
    annotation("javax.persistence.MappedSuperclass")
    annotation("jakarta.persistence.Entity")
    annotation("jakarta.persistence.Embeddable")
    annotation("jakarta.persistence.MappedSuperclass")
}

group = "de.fraunhofer.iem"
version = "0.0.2-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_21
configurations {
    compileOnly {
        extendsFrom(configurations.annotationProcessor.get())
    }
}

repositories {
    mavenCentral()
}

val coroutineVersion = "1.7.3"
val ktorVersion = "2.3.7"
dependencies {
//    detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.3")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa:$springVersion")
    implementation("org.springframework.boot:spring-boot-starter-validation:$springVersion")
    implementation("org.springframework.boot:spring-boot-starter-security:$springVersion")
    implementation("org.springframework.boot:spring-boot-starter-webflux:$springVersion")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.16.0")
    implementation("org.jetbrains.kotlin:kotlin-reflect:1.9.21")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive:$coroutineVersion")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$coroutineVersion")
    implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.2.0")
    implementation("org.gitlab4j:gitlab4j-api:6.0.0-rc.2")
    implementation("org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
    implementation("org.springframework.boot:spring-boot-starter-actuator:$springVersion")
    implementation("io.ktor:ktor-client-core-jvm:$ktorVersion")
    implementation("io.ktor:ktor-client-cio-jvm:$ktorVersion")
    implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
    implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
    developmentOnly("org.springframework.boot:spring-boot-devtools:$springVersion")
    runtimeOnly("org.postgresql:postgresql:42.6.0")
    testImplementation("org.springframework.boot:spring-boot-starter-test:$springVersion") {
        exclude(module = "mockito-core")
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
    testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
    testRuntimeOnly("com.h2database:h2:2.2.224")
    testImplementation("com.ninja-squad:springmockk:4.0.2")
    testImplementation("org.springframework.security:spring-security-test:6.1.5")
    testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutineVersion")
}
//
//detekt {
//    // Version of detekt that will be used. When unspecified the latest detekt
//    // version found will be used. Override to stay on the same version.
//    toolVersion = "1.23.1"
//
//    // The directories where detekt looks for source files.
//    // Defaults to `files("src/main/java", "src/test/java", "src/main/kotlin", "src/test/kotlin")`.
//    source.setFrom("src/main/java", "src/main/kotlin")
//
//    // Builds the AST in parallel. Rules are always executed in parallel.
//    // Can lead to speedups in larger projects. `false` by default.
//    parallel = false
//
//    // Define the detekt configuration(s) you want to use.
//    // Defaults to the default detekt configuration.
//    config.setFrom("config/detekt.yml")
//
//    // Applies the config files on top of detekt's default config file. `false` by default.
//    buildUponDefaultConfig = true
//
//    // Turns on all the rules. `false` by default.
//    allRules = false
//
//    // Specifying a baseline file. All findings stored in this file in subsequent runs of detekt.
//    baseline = file("config/baseline.xml")
//
//    // Disables all default detekt rulesets and will only run detekt with custom rules
//    // defined in plugins passed in with `detektPlugins` configuration. `false` by default.
//    disableDefaultRuleSets = false
//
//    // Adds debug output during task execution. `false` by default.
//    debug = false
//
//    // If set to `true` the build does not fail when the
//    // maxIssues count was reached. Defaults to `false`.
//    ignoreFailures = false
//
//    // Android: Don't create tasks for the specified build types (e.g. "release")
//    ignoredBuildTypes = listOf("release")
//
//    // Android: Don't create tasks for the specified build flavor (e.g. "production")
//    ignoredFlavors = listOf("production")
//
//    // Android: Don't create tasks for the specified build variants (e.g. "productionRelease")
//    ignoredVariants = listOf("productionRelease")
//
//    // Specify the base path for file paths in the formatted reports.
//    // If not set, all file paths reported will be absolute file path.
//    basePath = projectDir.absolutePath
//}
//
//configurations.all {
//    resolutionStrategy.eachDependency {
//        if (requested.group == "org.jetbrains.kotlin") {
//            useVersion("1.9.21")
//        }
//    }
//}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "21"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}