repositories {
    maven { url = "https://jitpack.io" }
}
def textVersion = "3.0.2"

dependencies {
    implementation("org.yaml:snakeyaml:1.25")
    implementation("com.google.code.gson:gson:2.8.6") {
        because("Minecraft uses GSON 2.8.0")
        force = true
    }
    implementation("org.projectlombok:lombok:1.18.12")
    compileOnly("org.projectlombok:lombok:1.18.12")
    testCompileOnly("org.projectlombok:lombok:1.18.8")
    annotationProcessor("org.projectlombok:lombok:1.18.8")
    testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
    implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72")
    implementation("org.jetbrains:annotations:19.0.0")
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

processResources {
    from("src/main/resources") {
        include "plugin.properties"
        expand(
                version: "${project.parent.version}",
                name: project.parent.name,
                commit: "${git.head().abbreviatedId}",
                date: "${git.head().getDate().format("yy.MM.dd")}",
        )
    }
}

//noinspection GroovyAssignabilityCheck
jar.archiveFileName = "PlotSquared-${project.parent.version}.jar"
jar.destinationDirectory = file("../mvn/com/plotsquared/PlotSquared/" + project.parent.version)
task createPom {
    doLast {
        pom {
            project {
                groupId = rootProject.group
                artifactId = "PlotSquared"
                version = project.parent.version
            }
        }.writeTo("../mvn/com/plotsquared/PlotSquared/${project.parent.version}/PlotSquared-${project.parent.version}.pom")
        pom {
            project {
                groupId = rootProject.group
                artifactId = "PlotSquared"
                version = "latest"
            }
        }.writeTo("../mvn/com/plotsquared/PlotSquared/latest/PlotSquared-latest.pom")
         .writeTo("pom.xml")
    }
}

task copyFiles {
    doLast {
        copy {
            from("../mvn/com/plotsquared/PlotSquared/${project.parent.version}/")
            into("../mvn/com/plotsquared/PlotSquared/latest/")
            include("*.jar")
            rename("PlotSquared-${project.parent.version}.jar", "PlotSquared-latest.jar")
        }
    }
}

shadowJar {
    dependencies {
        include(dependency("net.kyori:text-api:3.0.2"))
        include(dependency("net.kyori:text-serializer-gson:3.0.2"))
        include(dependency("net.kyori:text-serializer-legacy:3.0.2"))
        include(dependency("net.kyori:text-serializer-plain:3.0.2"))
    }
    relocate('net.kyori.text', 'com.plotsquared.formatting.text')
    relocate("org.json", "com.plotsquared.json")
}

shadowJar.doLast {
    task ->
        ant.checksum file: task.archivePath
}

build.dependsOn(shadowJar)

build.finalizedBy(copyFiles)
copyFiles.dependsOn(createPom)
