plugins {
    id "java"
    id "org.jetbrains.kotlin.jvm" version "1.6.20"
    id "com.github.johnrengelman.shadow" version "7.1.2"
    id "com.vanniktech.maven.publish" version "0.19.0"
    id "org.jlleitschuh.gradle.ktlint" version "10.2.1"
    id "com.github.ben-manes.versions" version "0.42.0"
}

repositories {
    mavenCentral()
    google()
}

ktlint {
    version = "0.34.2"
}

dependencies {
    // This includes the kotlin runtime in to the fat jar
    implementation "com.github.javaparser:javaparser-symbol-solver-core:3.24.2"
    implementation "com.github.ajalt.clikt:clikt:3.4.1"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.20"

    testImplementation "junit:junit:4.13.2"
    testImplementation "com.google.truth:truth:1.1.3"
    testImplementation "org.jetbrains.kotlin:kotlin-test-junit:1.6.20"
    testImplementation "org.jetbrains.kotlin:kotlin-test-annotations-common:1.6.20"
    testImplementation "org.jetbrains.kotlin:kotlin-test-common:1.6.20"
    testImplementation "org.jetbrains.kotlin:kotlin-test:1.6.20"

    // Source: https://github.com/kotlinx/ast
    // This includes the compiled libraries for 
    // com.github.kotlinx.ast:grammar-kotlin-parser-antlr-kotlin:bf1da05656;
    // It's included largely because there are no published packages for it outside
    // of jitpack.
    implementation files("libs/common-jvm-bf1da05656.jar")
    implementation files("libs/grammar-kotlin-parser-antlr-kotlin-jvm-bf1da05656.jar")
    implementation files("libs/grammar-kotlin-parser-common-jvm-bf1da05656.jar")
    implementation files("libs/parser-antlr-kotlin-jvm-bf1da05656.jar")
    implementation files("libs/antlr-kotlin-runtime-jvm-710f0f8b7f.jar")
}

compileKotlin {
    kotlinOptions.jvmTarget = "11"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "11"
}

test {
    // This is required for an issue integrating Kotlin with newer JVMs:
    // https://youtrack.jetbrains.com/issue/IDEA-248785
    jvmArgs "--illegal-access=permit"
}

jar {
    dependsOn(shadowJar)

    manifest {
        attributes "Main-Class": "com.dropbox.mobile.hypershard.HypershardKt"
    }
}

shadowJar {
    minimize()
}

allprojects {
    plugins.withId("com.vanniktech.maven.publish") {
        mavenPublish {
            sonatypeHost = "S01"
        }
    }
}
