buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
    }
}

plugins {
    id 'org.springframework.boot' version '2.7.18'
    id 'java'
    id 'io.spring.dependency-management' version '1.1.5'
    id 'org.jetbrains.kotlin.jvm' version "$kotlinVersion"
    id 'org.jetbrains.kotlin.plugin.spring' version "$kotlinVersion"
    id 'org.jetbrains.kotlin.plugin.jpa' version "$kotlinVersion"
    id 'org.jetbrains.kotlin.plugin.allopen' version "$kotlinVersion"
    id "org.jlleitschuh.gradle.ktlint" version "11.6.1"
}

group 'net.glenmazza'
version '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_17

repositories {
    mavenCentral()
}

sourceSets {
    main {
        resources {
            srcDirs = ["src/main/kotlin","src/main/resources"]
            excludes = ["**/*.java"]
        }
    }
    integrationTest {
        java {
            srcDir file('src/itest/kotlin')
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            integrationTest.runtimeClasspath += integrationTest.output
            include '**/*.kt'
        }
        resources.srcDir file('src/itest/resources')
    }
}

configurations {
    integrationTestImplementation.extendsFrom implementation, testImplementation
    integrationTestRuntimeOnly.extendsFrom runtimeOnly
}

task integrationTest(type: Test) {
    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
    outputs.upToDateWhen { false }
    mustRunAfter test
}

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    implementation group: 'commons-codec', name: 'commons-codec', version: '1.16.1'
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.14.0'
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
    testImplementation 'org.jetbrains.kotlin:kotlin-test'
    testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.8.1'
    testImplementation 'org.mockito.kotlin:mockito-kotlin:4.1.0'
}

check.dependsOn integrationTest

integrationTest {
    useJUnitPlatform()
}

task sourcesJar(type: Jar) {
    from sourceSets.main.kotlin.srcDirs
    archiveClassifier = 'sources'
}

bootJar.enabled = false
jar.enabled = true
