plugins {
    id 'com.github.johnrengelman.shadow' version '8.1.1'
    id 'org.jetbrains.kotlin.jvm' version "${kotlin_version}"
}

def getVersionFromFile(String fileName) {
    def versionFile = file(fileName)
    if (versionFile.exists()) {
        return versionFile.text.trim()
    } else {
        throw new Exception("File not found: ${versionFile.absolutePath}") as Throwable
    }
}

def tool_version = getVersionFromFile('../../tool_version.txt')

def mod_version = getVersionFromFile('../../version.txt')

group = mod_group_id
version = mod_version

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url = uri(maven_repository_url)
        credentials {
            username = System.getenv("GH_USERNAME")
            password = System.getenv("PACKAGE_READ_ONLY_TOKEN")
        }
    }
}

dependencies {
    implementation "com.github.theword.queqiao:queqiao-tool:${tool_version}"
    implementation "org.java-websocket:Java-WebSocket:${java_websocket_version}"
    implementation "org.yaml:snakeyaml:${snakeyaml_version}"
    implementation "org.slf4j:slf4j-api:${slf4j_version}"
    implementation "org.slf4j:slf4j-simple:${slf4j_version}"
    implementation "com.google.code.gson:gson:${gson_version}"
    implementation "commons-io:commons-io:${commons_io_version}"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
    implementation "org.glavo:rcon-java:${glavoRconVersion}"

    testImplementation 'org.jetbrains.kotlin:kotlin-test'
}

test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
    }
}

kotlin {
    jvmToolchain(8)
}

shadowJar {
    archiveBaseName.set("${mod_name}-minecraft+origin")
    archiveClassifier.set("")
    destinationDirectory.set(file("../../QueQiao-jar/${version}"))
    manifest {
        attributes(
                'Main-Class': 'com.github.theword.queqiao.QueQiao' // 替换为你的主类路径
        )
    }
    dependencies {
        include(dependency("com.github.theword.queqiao:queqiao-tool:${tool_version}"))
        include(dependency("org.java-websocket:Java-WebSocket:${java_websocket_version}"))
        include(dependency("org.yaml:snakeyaml:${snakeyaml_version}"))
        include(dependency("org.slf4j:slf4j-api:${slf4j_version}"))
        include(dependency("org.slf4j:slf4j-simple:${slf4j_version}"))
        include(dependency("com.google.code.gson:gson:${gson_version}"))
        include(dependency("commons-io:commons-io:${commons_io_version}"))
        include(dependency("org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"))
    }
    mergeServiceFiles()
}

tasks.build {
    dependsOn shadowJar
}