// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // publish plugin for bintray
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenLocal()
        google()
    }

    // this is needed for running plugin tests
    configurations.all {
        resolutionStrategy {
            force 'org.codehaus.groovy:groovy-all:2.4.12'
        }
    }

    if (!['Blade', 'sample', 'module'].contains(project.name)) {

        println " --> $project.name "

        group = LIB_GROUP_ID
        version = LIB_VERSION

        apply plugin: 'java-library'
        apply plugin: 'maven'
        apply plugin: 'maven-publish'
        apply plugin: 'com.jfrog.bintray'

        /* Prevents sporadic compilation error:
        * 'Bad service configuration file, or exception thrown while constructing
        *  Processor object: javax.annotation.processing.Processor: Error reading
        *  configuration file'
        *
        * See https://discuss.gradle.org/t/gradle-not-compiles-with-solder-tooling-jar/7583/20
        */
        tasks.withType(JavaCompile) { options.fork = true }

        File privateProperties = rootProject.file('private.properties')
        if (privateProperties.exists()) {
            ext.priv = parseConfig(privateProperties)

            task srcJar(type: Jar) {
                from sourceSets.main.allJava
                classifier "sources"
            }

            task docJar(type: Jar) {
                classifier "javadoc"
            }

            artifacts {
                archives srcJar
                archives docJar
            }

            bintray {
                dryRun false

                user = priv.BINTRAY_USER
                key = priv.BINTRAY_KEY

                configurations = ['archives']

                pkg {
                    repo = LIB_REPO_NAME
                    name = LIB_PACKAGE_NAME
                    licenses = LIB_LICENSES
                    vcsUrl = LIB_GIT_URL

                    version {
                        name = LIB_VERSION
                        desc = LIB_VERSION_DESC
                    }
                }
            }
        }
    }
}

ext.deps = [
        /* Android */
        // Android 4.0.x (http://mvnrepository.com/artifact/com.google.android/android)
        android_runtime    : 'com.google.android:android:4.0.1.2',
        google_support_v4  : 'com.google.android:support-v4:r7',
        support_annotations: 'com.android.support:support-annotations:23.0.1',
        // Javax Annotations (@Generated)
        javax_annotations  : 'org.glassfish:javax.annotation:10.0-b28',

        // Square
        javapoet           : 'com.squareup:javapoet:1.11.1',

        // Dagger2
        dagger2            : 'com.google.dagger:dagger:2.11',
        dagger2_compiler   : 'com.google.dagger:dagger-compiler:2.11',

        // Plugin
        javassist_helper   : 'eu.f3rog.javassist:helper:0.1.10',
        gradle_plugin      : 'com.android.tools.build:gradle:3.2.1',
        snakeyaml          : 'org.yaml:snakeyaml:1.17',

        // Test dependencies
        junit              : 'junit:junit:4.12',
        guava              : 'com.google.guava:guava:26.0',
        truth              : 'com.google.truth:truth:0.42',
        compiletesting     : 'com.google.testing.compile:compile-testing:0.15',
        autoservice        : 'com.google.auto.service:auto-service:1.0-rc4',
        autocommon         : 'com.google.auto:auto-common:0.10',
        groovy_all         : 'org.codehaus.groovy:groovy-all:2.4.12',
        spock              : 'org.spockframework:spock-core:1.2-groovy-2.4'
]

def parseConfig(File config) {
    config.withReader {
        def prop = new Properties()
        prop.load(it)
        return (new ConfigSlurper().parse(prop))
    }
}