plugins {
    id 'org.springframework.boot' version '3.3.2'
    id 'io.spring.dependency-management' version '1.1.6'
    id 'org.jetbrains.kotlin.plugin.jpa' version '1.9.24'
    id 'org.jetbrains.kotlin.jvm' version '1.9.24'
    id 'org.jetbrains.kotlin.plugin.spring' version '1.9.24'
    id 'jacoco'
}

group = 'com.flab'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

apply plugin: 'kotlin-spring'
apply plugin: 'kotlin-jpa'

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

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-data-redis'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-cache'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'


    implementation 'org.springframework.boot:spring-boot-starter-amqp'


    runtimeOnly 'io.micrometer:micrometer-registry-prometheus'

    implementation 'com.aventrix.jnanoid:jnanoid:2.0.0'
    implementation 'com.google.zxing:javase:3.5.3'

    implementation 'io.jsonwebtoken:jjwt-api:0.12.6'
    runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.6'
    runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.6'
    implementation 'com.linecorp.kotlin-jdsl:jpql-dsl:3.5.1'
    implementation 'com.linecorp.kotlin-jdsl:jpql-render:3.5.1'
    implementation 'com.linecorp.kotlin-jdsl:spring-data-jpa-support:3.5.1'

    implementation 'com.github.ben-manes.caffeine:caffeine'
    runtimeOnly "com.mysql:mysql-connector-j"
    implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'

//    runtimeOnly 'com.oracle.database.jdbc:ojdbc11'
//    implementation 'com.oracle.database.security:osdt_cert'
//    implementation 'com.oracle.database.security:oraclepki'
//    implementation 'com.oracle.database.security:osdt_core'

    implementation 'net.logstash.logback:logstash-logback-encoder:8.0'

    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
    implementation platform('com.oracle.oci.sdk:oci-java-sdk-bom:3.54.0')
    implementation 'com.oracle.oci.sdk:oci-java-sdk-objectstorage'
    implementation 'com.oracle.oci.sdk:oci-java-sdk-common'
    implementation 'com.oracle.oci.sdk:oci-java-sdk-common-httpclient-jersey3'
//    implementation 'io.micrometer:micrometer-tracing-bridge-brave'
//    implementation 'io.zipkin.reporter2:zipkin-reporter-brave'
//    implementation 'com.github.gavlyukovskiy:datasource-proxy-spring-boot-starter:1.9.2'


    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.kotest:kotest-assertions-core-jvm:5.9.1'
    testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.9.1'
    implementation 'io.kotest.extensions:kotest-extensions-spring:1.3.0'
    testImplementation 'com.h2database:h2:2.3.230'
    testImplementation 'io.mockk:mockk:1.13.12'
    testImplementation 'com.ninja-squad:springmockk:4.0.2'
    testImplementation 'com.github.codemonstur:embedded-redis:1.4.3'
    testImplementation 'com.icegreen:greenmail:2.0.1'
    testImplementation 'com.squareup.okhttp3:okhttp:4.12.0'
    testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
    implementation "org.springframework.boot:spring-boot-starter-aop"
    testImplementation 'org.testcontainers:elasticsearch:1.20.3'
    testImplementation 'org.testcontainers:junit-jupiter:1.20.3'

}

kotlin {
    compilerOptions {
        freeCompilerArgs.addAll '-Xjsr305=strict'
    }
}

tasks.named('test') {
    useJUnitPlatform()
}

tasks.named("jar") {
    enabled = false // Plain jar이 생성되지 않도록 제한
}

jacoco {
    toolVersion = '0.8.12'
}

jacocoTestReport {
    dependsOn test
    reports {
        html.required.set true
        xml.required.set true
        csv.required.set false
    }

    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: [
                    "com/flab/ticketing/**/TicketingApplication.*",
                    "com/flab/ticketing/**/TicketingApplicationKt.*",
                    "com/flab/ticketing/**/dto/*",
                    "com/flab/ticketing/**/exception/*",
                    "**/config/*"
            ])
        }))
    }

}


task testCoverage(type: Test) {
    group 'verification'
    description 'Runs the unit tests with coverage'

    dependsOn(':test',
            ':jacocoTestReport',
            ':jacocoTestCoverageVerification')

    tasks['jacocoTestReport'].mustRunAfter(tasks['test'])
    tasks['jacocoTestCoverageVerification'].mustRunAfter(tasks['jacocoTestReport'])
}