buildscript {
    repositories {
        jcenter()
    }
    
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'kotlin'
apply plugin: 'application'

group 'com.webrtc.ktor.server'
version '0.0.1'
mainClassName = "io.ktor.server.netty.EngineMain"

sourceSets {
    main.kotlin.srcDirs = main.java.srcDirs = ['src']
    test.kotlin.srcDirs = test.java.srcDirs = ['test']
    main.resources.srcDirs = ['resources']
    test.resources.srcDirs = ['testresources']
}

repositories {
    mavenLocal()
    jcenter()
    maven { url 'https://kotlin.bintray.com/ktor' }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation "io.ktor:ktor-server-netty:$ktor_version"
    implementation "ch.qos.logback:logback-classic:$logback_version"
    implementation "io.ktor:ktor-client-core:$ktor_version"
    implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
    implementation "io.ktor:ktor-client-cio:$ktor_version"
    implementation "io.ktor:ktor-server-core:$ktor_version"
    implementation "io.ktor:ktor-websockets:$ktor_version"
    implementation "io.ktor:ktor-client-websockets:$ktor_version"
    implementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
    testImplementation "io.ktor:ktor-server-tests:$ktor_version"
}

// JAR task configuration to include the main class in the manifest
jar {
    manifest {
        attributes(
                'Main-Class': mainClassName,  // Sets the Main-Class attribute for JAR execution
                'Implementation-Title': project.name,
                'Implementation-Version': project.version
        )
    }
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE  // Exclude duplicate files
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }  // Include dependencies in the JAR
    }
}