dependencies {
    shadow project(path: ":api")
    shadow project(path: ":extensions")
    shadow project(path: ":common")
    shadow project(path: ":common", configuration: "swaggerJson")
    shadow project(path: ":bukkit")
    shadow project(path: ":nukkit")
    shadow project(path: ":sponge")
    shadow project(path: ":bungeecord")
    shadow project(path: ":velocity")
    testImplementation project(path: ":common", configuration: 'testArtifacts')
    testImplementation project(path: ":bukkit", configuration: 'testArtifacts')
    testImplementation project(path: ":nukkit", configuration: 'testArtifacts')
    testImplementation project(path: ":sponge", configuration: 'testArtifacts')
    testImplementation project(path: ":bungeecord", configuration: 'testArtifacts')
    testImplementation project(path: ":velocity", configuration: 'testArtifacts')
}

jar {
    // Add the sponge mixin into the manifest
    manifest.attributes([
            'MixinConfigs': 'plan-sponge.mixins.json'
    ])
}

shadowJar {
    dependsOn processResources
    configurations = [project.configurations.shadow]

    from findProject(':extensions:adventure').tasks.shadowJar.archiveFile

    // Exclude these files
    exclude "**/*.svg"
    exclude "**/*.psd"
    exclude "**/*.map"
    exclude "LICENSE*.txt"
    exclude "jetty-dir.css"

    exclude "**/module-info.class"
    exclude "module-info.class"
    exclude 'META-INF/versions/' // Causes Sponge to crash
    exclude 'mozilla/**/*'

    // Exclude extra dependencies
    exclude 'org/apache/http/**/*' // Unnecessary http client depended on by geolite2 implementation
    exclude "org/junit/**/*" // see extensions/build.gradle
    exclude "org/opentest4j/**/*" // see extensions/build.gradle
    exclude "org/checkerframework/**/*" // Dagger compiler
    exclude "com/google/common/**/*"
    exclude "com/google/thirdparty/**/*"
    // Exclude swagger
    exclude "org/yaml/**/*"
    exclude "nonapi/**/*"
    exclude "io/github/classgraph/**/*"
    exclude "io/swagger/**/*"
    exclude "com/sun/activation/**/*"
    exclude "jakarta/activation/**/*"
    exclude "jakarta/validation/**/*"
    exclude "jakarta/ws/**/*"
    exclude "jakarta/xml/**/*"
    exclude "javassist/**/*"

    relocate('org.slf4j', 'plan.org.slf4j')

    // Unrelocate a package to use platform version of some libraries that were relocated in Plan
    exclude "com/djrapitops/plan/unrelocate/**/*"
    relocate('com.djrapitops.plan.unrelocate.', '')

    relocate('org.apache', 'plan.org.apache') {
        exclude 'org/apache/logging/**'
        exclude 'org/apache/maven/**' // This needs to be unrelocated for Sponge
    }
    relocate 'dagger', 'plan.dagger'
    // Don't relocate MySQL or SQLite since they are loaded with a isolated class loader
    // relocate 'org.sqlite', 'plan.org.sqlite'
    // relocate 'com.mysql', 'plan.com.mysql'
    // relocate 'com.google.protobuf', 'plan.com.mysql.cj.x.google.protobuf'
    relocate 'javax.inject', 'plan.javax.inject'
    relocate 'com.github.benmanes', 'plan.com.github.benmanes'
    relocate 'dev.vankka.dependencydownload', 'plan.dev.vankka.dependencydownload'

    relocate 'com.maxmind', 'plan.com.maxmind'
    relocate 'com.fasterxml', 'plan.com.fasterxml'
    relocate 'com.zaxxer', 'plan.com.zaxxer'
    relocate 'com.google.gson', 'plan.com.google.gson'
    relocate 'com.google.errorprone', 'plan.com.google.errorprone'
    relocate 'org.bstats', 'plan.org.bstats'

    relocate 'org.eclipse.jetty', 'plan.org.eclipse.jetty'
    relocate 'jakarta.servlet', 'plan.jakarta.servlet'
    relocate 'javax.servlet', 'plan.javax.servlet'

    relocate 'org.json.simple', 'plan.org.json.simple'

    destinationDirectory.set(file("$rootDir/builds/"))
    archiveBaseName.set('Plan')
    archiveClassifier.set('')

    mergeServiceFiles()

    build {
        dependsOn tasks.named("shadowJar")
    }
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = 'com.djrapitops'
            artifactId = 'Plan-plugin'
            version = "$fullVersion"

            artifact shadowJar
        }
    }
}
