/*
 * Copyright (c) 2019, Lucas <https://github.com/Lucwousin>
 *               2022, Owain van Brakel <https://github.com/Owain94>
 * All rights reserved.
 *
 * This code is licensed under GPL3, see the complete license in
 * the LICENSE file in the root directory of this source tree.
 */
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("java-gradle-plugin")
    kotlin("jvm") version "1.9.24"
    `maven-publish`
}

val oprsver = "4.31.2"

group = "com.openosrs"
version = "2.0.2"

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    annotationProcessor(group = "org.projectlombok", name = "lombok", version = "1.18.34")
    compileOnly(group = "org.projectlombok", name = "lombok", version = "1.18.34")

    implementation(group = "org.ow2.asm", name = "asm", version = "9.6")
    implementation(group = "org.ow2.asm", name = "asm-util", version = "9.6")
    implementation(group = "org.jetbrains", name = "annotations", version = "22.0.0")
    implementation(group = "com.google.guava", name = "guava", version = "30.1.1-jre") {
        exclude(group = "com.google.code.findbugs", module = "jsr305")
        exclude(group = "com.google.errorprone", module = "error_prone_annotations")
        exclude(group = "com.google.j2objc", module = "j2objc-annotations")
        exclude(group = "org.codehaus.mojo", module = "animal-sniffer-annotations")
    }
    implementation("com.openosrs:deobfuscator:${oprsver}") {
        isTransitive = false
    }

    testCompileOnly(group = "com.openosrs", name = "injection-annotations", version = "1.1")
    testImplementation(group = "junit", name = "junit", version = "4.12")
}

gradlePlugin {
    plugins {
        create("injectorPlugin") {
            id = "com.openosrs.injector"
            implementationClass = "com.openosrs.injector.InjectPlugin"
        }
    }
}

configure<JavaPluginExtension> {
    sourceCompatibility = JavaVersion.VERSION_21
    targetCompatibility = JavaVersion.VERSION_21
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21)

val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_21)

val sourcesJar by tasks.registering(Jar::class) {
    archiveClassifier.set("sources")
    from(sourceSets.main.get().allSource)
}

publishing {
    repositories {
        maven {
            url = uri("$buildDir/repo")
        }
        if (System.getenv("REPO_URL") != null) {
            maven {
                url = uri(System.getenv("REPO_URL"))
                credentials {
                    username = System.getenv("REPO_USERNAME")
                    password = System.getenv("REPO_PASSWORD")
                }
            }
        }
    }
    publications {
        register("mavenJava", MavenPublication::class) {
            from(components["java"])
            artifact(sourcesJar.get())
        }
    }
}
