plugins {
    id("java")
}

group = "de.srsoftware"
version = "unspecified"

repositories {
    mavenCentral()
}

dependencies {
    implementation("de.srsoftware:tools.util:2.0.4")
    implementation("org.xerial:sqlite-jdbc:3.49.0.0")
    testImplementation(platform("org.junit:junit-bom:5.10.0"))
    testImplementation("org.junit.jupiter:junit-jupiter")
}


tasks.jar {
    manifest.attributes["Main-Class"] = "de.srsoftware.umbrella.core.Launcher"
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    val dependencies = configurations
        .runtimeClasspath
        .get()
        .map(::zipTree) // OR .map { zipTree(it) }
    from(dependencies)
}

fun download(url : String, destination : String){
    var destFile = projectDir.toPath().resolve(destination).toFile();
    destFile.parentFile.mkdirs()
    if (!destFile.exists()) {
        System.out.println("Downloading "+url)
        ant.invokeMethod("get", mapOf("src" to url, "dest" to destFile))
    }
}

tasks.register("downloadLib"){
    download("https://github.com/AshurAxelR/JParsedown/raw/refs/heads/master/src/com/xrbpowered/jparsedown/JParsedown.java", "src/main/java/com/xrbpowered/jparsedown/JParsedown.java")
}

tasks.withType<org.gradle.jvm.tasks.Jar>() {
    exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
}

tasks.named("compileJava") {
    dependsOn("downloadLib")
}
