
plugins {
    id 'java-library'
    id 'jacoco'
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    api 'org.springframework.boot:spring-boot-starter-logging:3.2.3'
    api 'org.apache.commons:commons-lang3:3.14.0'
    api 'org.apache.commons:commons-collections4:4.4'
    api 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
    api 'org.reflections:reflections:0.10.2'
    api "org.projectlombok:lombok:$lombokVersion"
    annotationProcessor("org.projectlombok:lombok:$lombokVersion")

    testImplementation 'ch.qos.logback:logback-classic:1.4.14'
    testImplementation 'com.github.stefanbirkner:system-rules:1.19.0'
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'net.bytebuddy:byte-buddy:1.14.12'
    testImplementation 'org.assertj:assertj-core:3.27.3'
    testImplementation 'org.mockito:mockito-core:5.17.0'
    testImplementation 'org.awaitility:awaitility:4.3.0'
    testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.19.3'
    testAnnotationProcessor("org.projectlombok:lombok:$lombokVersion")
}

group = 'by.andd3dfx'
version = '1.0-SNAPSHOT'
description = 'java-interview-coding'
java.sourceCompatibility = JavaVersion.VERSION_21
java.targetCompatibility = JavaVersion.VERSION_21

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'
}

tasks.withType(Test).configureEach {
    testLogging {
        events "passed", "skipped", "failed",
                // "standardOut",   // Uncomment to get all logs during tests execution
                "standardError"
    }
    afterSuite { desc, result ->
        if (!desc.parent)
            println("${result.resultType} " +
                    "(${result.testCount} tests, " +
                    "${result.successfulTestCount} successes, " +
                    "${result.failedTestCount} failures, " +
                    "${result.skippedTestCount} skipped)")
    }

    finalizedBy jacocoTestReport    // report is always generated after tests run
    jacoco {
        destinationFile = layout.buildDirectory.file('jacoco/jacocoTest.exec').get().asFile
        classDumpDir = layout.buildDirectory.dir('jacoco/classpathdumps').get().asFile
    }
}

jacocoTestReport {
    reports {
        csv.required = true
        xml.required = true
        html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
    }
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: [
                    '**/domain/**',
                    '**/dto/**',
                    '**/refactoring*/initial/**',
                    '**/core/howto/**',
                    '**/core/predict/**',
            ])
        }))
    }
}

tasks.register('githubWorkflowTest', Test) {
    exclude '**/**AddMultithreadingTest.class'
    exclude '**/**BlockingQueueTest.class'
    exclude '**/**DeadlockTest.class'
    exclude '**/**LivelockTest.class'
}
