plugins {
    id 'java'
    id 'org.springframework.boot' version '3.2.3'
    id 'io.spring.dependency-management' version '1.1.4'
    id 'org.asciidoctor.jvm.convert' version '3.3.2'
    id 'com.diffplug.spotless' version '6.23.3'
    id "io.sentry.jvm.gradle" version "4.11.0"
}

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

java {
    sourceCompatibility = '17'
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

ext {
    set('snippetsDir', file("build/generated-snippets"))
}

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2023.0.2'
        mavenBom 'org.springframework.modulith:spring-modulith-bom:1.3.3'
    }
}


dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'com.h2database:h2'
    runtimeOnly 'com.mysql:mysql-connector-j'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    // Lombok
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    testCompileOnly 'org.projectlombok:lombok'
    testAnnotationProcessor 'org.projectlombok:lombok'

    // Spring Security
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    testImplementation 'org.springframework.security:spring-security-test'

    // JWT
    implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
    runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
    runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

    // Redis
    implementation 'org.springframework.boot:spring-boot-starter-data-redis'

    // Querydsl
    implementation 'com.querydsl:querydsl-jpa:5.1.0:jakarta'
    annotationProcessor 'com.querydsl:querydsl-apt:5.1.0:jakarta'
    annotationProcessor "jakarta.annotation:jakarta.annotation-api"
    annotationProcessor "jakarta.persistence:jakarta.persistence-api"

    // Swagger
    implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'

    // Actuator
    implementation 'org.springframework.boot:spring-boot-starter-actuator'

    // Discord
    implementation 'net.dv8tion:JDA:5.0.0-beta.20'

    // Spring AOP
    implementation 'org.springframework.boot:spring-boot-starter-aop'

    // Mail
    implementation 'org.springframework.boot:spring-boot-starter-mail'

    // Excel
    implementation 'org.apache.poi:poi:5.2.5'

    // Monitoring
    implementation 'io.micrometer:micrometer-registry-prometheus'

    // OpenFeign
    implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
    implementation 'io.github.openfeign:feign-jackson'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'

    // Github
    implementation 'org.kohsuke:github-api:1.323'

    // Sentry
    implementation 'io.sentry:sentry-logback:7.14.0'
    implementation 'io.sentry:sentry-openfeign:7.14.0'

    // Spring Modulith
    implementation 'org.springframework.modulith:spring-modulith-starter-jpa'
}

tasks.named('test') {
    outputs.dir snippetsDir
    useJUnitPlatform()
}

tasks.named('asciidoctor') {
    inputs.dir snippetsDir
    dependsOn test
}

jar {
    enabled = false
}

spotless {
    format 'misc', {
        target '**/*.gradle', '**/*.md'
        trimTrailingWhitespace()
        indentWithSpaces(4)
        endWithNewline()
    }

    java {
        removeUnusedImports()
        palantirJavaFormat()
        formatAnnotations()
    }

    yaml {
        target '**/*.yml'
        prettier()
    }
}

tasks.register('updateGitHooks', Copy) {
    from './scripts/pre-commit'
    into '.git/hooks'

    compileJava.dependsOn(this)
}
