plugins {
    id 'application'
    id 'com.github.johnrengelman.shadow' version '4.0.4'
    id 'com.gorylenko.gradle-git-properties' version '2.0.0'
}

apply plugin: 'java'
apply plugin: 'idea'

version = '0.10.20'
group = 'com.avairebot'
description = 'AvaIre Discord Bot'
mainClassName = 'com.avairebot.Main'

sourceCompatibility = 1.8
targetCompatibility = 1.8

ext {
    moduleName = 'AvaIre'
}

shadowJar {
    archiveName = "AvaIre.jar"

    doLast {
        copy {
            from 'build/libs/AvaIre.jar'
            into '.'
        }
    }
}

tasks.withType(JavaCompile) {
    dependsOn 'clean'
    options.encoding = 'UTF-8'
    options.compilerArgs << "-Xlint:-unchecked"
}

task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'AvaIre: Discord Bot',
            'Implementation-Version': version,
            'Main-Class': 'com.avairebot.Main'
    }

    baseName = project.name

    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

javadoc {
    failOnError = false
    options.memberLevel = JavadocMemberLevel.PUBLIC
    options.author()
    options.encoding = 'UTF-8'
    options.addStringOption('-html5')
}

repositories {
    mavenCentral()                     // Main maven repo
    jcenter()                          // JDA and some other stuff
    mavenLocal()                       // Useful for developing
    maven { url "https://jitpack.io" } // Build projects directly from github

    // Used for pulling down JDA and LavaPlayer
    maven {
        name 'm2-dv8tion'
        url 'https://m2.dv8tion.net/releases'
    }
}

dependencies {
    compile group: 'com.avairebot', name: 'Shared', version: '80809049d2'
    compile group: 'net.dv8tion', name: 'JDA', version: '4.2.1_256'
    compile group: 'com.sedmelluq', name: 'lavaplayer', version: '1.3.75'
    compile group: 'com.sedmelluq', name: 'lavaplayer-ext-youtube-rotator', version: '0.2.3'
    compile group: 'com.sedmelluq', name: 'jda-nas', version: '1.1.0'
    compile group: 'com.github.FredBoat', name: 'Lavalink-Client', version: '4.0'

    compile group: 'commons-cli', name: 'commons-cli', version: '1.3.1'
    compile group: 'org.apache.commons', name: 'commons-text', version: '1.1'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
    compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
    compile group: 'org.yaml', name: 'snakeyaml', version: '1.19'
    compile group: 'org.jsoup', name: 'jsoup', version: '1.11.2'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.1'
    compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.46'
    compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.21.0.1'
    compile group: 'ai.api', name: 'libai', version: '1.6.12'

    compile group: 'com.sparkjava', name: 'spark-core', version: '2.7.1'
    compile group: 'io.prometheus', name: 'simpleclient', version: '0.1.0'
    compile group: 'io.prometheus', name: 'simpleclient_servlet', version: '0.1.0'
    compile group: 'io.prometheus', name: 'simpleclient_logback', version: '0.1.0'
    compile group: 'io.prometheus', name: 'simpleclient_hotspot', version: '0.1.0'
    compile group: 'io.prometheus', name: 'simpleclient_guava', version: '0.1.0'

    compile group: 'com.udojava', name: 'EvalEx', version: '1.18'
    compile group: 'com.vdurmont', name: 'emoji-java', version: '4.0.0'
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
    compile group: 'io.sentry', name: 'sentry-logback', version: '1.7.10'
    compile group: 'org.reflections', name: 'reflections', version: '0.9.11'

    // Tests
    // Only needed to run tests in a version of IntelliJ IDEA that bundles older versions
    compile("org.junit.platform:junit-platform-launcher:1.6.2")
    compile("org.junit.jupiter:junit-jupiter-engine:5.6.2")
    compile("org.junit.vintage:junit-vintage-engine:5.6.2")
}

import org.apache.tools.ant.filters.ReplaceTokens

processResources {
    filesMatching("**/app.properties") {
        filter ReplaceTokens, tokens: [
            "project.version"   : project.version,
            "project.groupId"   : project.group,
            "project.artifactId": project.ext.moduleName
        ]
    }
}
