repositories {
    flatDir {dirs 'lib'}
//    maven {url "https://repo.potestas.xyz/main/"}
}

clean { delete "../target" }

dependencies {
    compile project(':core')
//    compile 'cn.nukkit:nukkit:1.0-SNAPSHOT'
    compile name: 'nukkit-1.0-SNAPSHOT'
    compile name: 'worldedit-core-6.1.4-SNAPSHOT-dist'
}

processResources {
    from('src/main/resources') {
        include 'plugin.yml'
        expand(
                name: project.parent.name,
                version: project.parent.version
        )
    }
}

apply plugin: 'com.github.johnrengelman.shadow'

jar.archiveName="fawe-nukkit-${project.parent.version}.jar"
jar.destinationDir = file '../mvn/com/boydti/fawe-nukkit/' + project.parent.version
task createPom << {
    pom {
        project {
            groupId 'com.boydti'
            artifactId 'fawe-nukkit'
            version project.parent.version
        }
    }
    .getEffectivePom()
            .setDependencies(new ArrayList<>())
            .writeTo("../mvn/com/boydti/fawe-nukkit/${project.parent.version}/fawe-nukkit-${project.parent.version}.pom")
    pom {
        project {
            groupId 'com.boydti'
            artifactId 'fawe-nukkit'
            version 'latest'
        }
    }
    .getEffectivePom()
            .setDependencies(new ArrayList<>())
            .writeTo("../mvn/com/boydti/fawe-nukkit/latest/fawe-nukkit-latest.pom")
}
task copyFiles {
    doLast {
        copy {
            from "../mvn/com/boydti/fawe-nukkit/${project.parent.version}/"
            into '../mvn/com/boydti/fawe-nukkit/latest/'
            include('fawe-nukkit*.jar')
            rename ("fawe-nukkit-${project.parent.version}.jar", 'fawe-nukkit-latest.jar')
        }
    }
}

shadowJar {
    dependencies {
        include(dependency('com.github.luben:zstd-jni:1.1.1'))
//        include(dependency('org.javassist:javassist:3.22.0-CR1'))
        include(dependency('co.aikar:fastutil-lite:1.0'))
        include(dependency(name: 'worldedit-core-6.1.4-SNAPSHOT-dist'))
        include(dependency('com.google.code.gson:gson:2.2.4'))
        include(dependency('org.yaml:snakeyaml:1.16'))
        include(dependency('com.google.guava:guava:17.0'))
        include(dependency(':core'))
    }
    archiveName = "${parent.name}-${project.name}-${parent.version}.jar"
    destinationDir = file '../target'
    manifest {
        attributes("Main-Class": "com.boydti.fawe.nukkit.core.converter.ConverterFrame")
    }

    relocate('com.google.gson', 'com.sk89q.worldedit.internal.gson')
    relocate 'org.yaml.snakeyaml', 'com.boydti.fawe.yaml'
    relocate 'com.google.common', 'com.sk89q.worldedit.internal.common'
}
shadowJar.doLast {
    task ->
        ant.checksum file: task.archivePath
}

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