apply plugin: 'application'


archivesBaseName = 'server'

mainClassName = 'rs09.Server'

compileJava {
    options.encoding = "UTF-8"
}

compileKotlin {
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11
        freeCompilerArgs += '-XXLanguage:-NewInference'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.jetbrains.kotlin:kotlin-reflect:1.5.20'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
    implementation group: 'com.moandjiezana.toml', name: 'toml4j', version: '0.7.2'

    //Unit Tests
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'

    implementation files(
            "libs/PrimitiveExtensions-1.0.jar",
            "libs/ConstLib-1.4.jar",
            "libs/json-simple-1.1.1.jar",
            "libs/markdown-jvm-0.2.4.jar",
            "libs/classgraph-4.8.98.jar",
            "libs/mysql-connector-java-8.0.21.jar",
            "libs/mordant-jvm-2.0.0-alpha2.jar",
            "libs/colormath-jvm-2.0.0.jar",
            "libs/sqlite-jdbc.jar"
    )
}

test {
    useJUnitPlatform()
    dependsOn cleanTest
    testLogging.showStandardStreams = true
    testLogging {
        events "passed", "skipped", "failed"
        info.events = debug.events
        info.exceptionFormat = debug.exceptionFormat

        afterSuite { desc, result ->
            if (!desc.parent) { // will match the outermost suite
                def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)"
                def startItem = '|  ', endItem = '  |'
                def repeatLength = startItem.length() + output.length() + endItem.length()
                println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
            }
        }
    }
}

/*sourceSets {
    main.java.srcDirs = ['src/main/java']
    main.kotlin.srcDirs = ['src/main/kotlin']
}*/

jar {
    manifest {
        attributes 'Main-Class': 'rs09.Server'
    }
    from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
}