
buildscript {
    println("${project.name}: buildscript")

    // rootProject.buildscript 里用的变量, 由于调用时机比 "闭包project.ext{ ... }" 早, 故不能写在那边
//    project.ext.kotlin_version = "1.1.3-2"
//    project.ext.android_plugin_version = "2.2.0"
    // 导入 external 全局变量
    apply from: "ext.gradle"

    repositories {
        jcenter()
        maven { url 'https://maven.google.com/' }
    }
    dependencies {
        classpath _android.plugin

        classpath _kotlin.kotlin_gradle_plugin
        classpath _kotlin.kotlin_android_extensions
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com/' }
    }
}

subprojects {
    def isAppModule = it.name.equals('app')
    def enableDataBinding = isAppModule || it.name.equals('databinding')

    apply plugin: isAppModule? 'com.android.application': 'com.android.library'

    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'   // 拓展

    // kapt
    apply plugin: 'kotlin-kapt'
    kapt {
        generateStubs = true
    }

    android {
        compileSdkVersion _android.compileSdkVersion as Integer
        buildToolsVersion _android.buildToolsVersion as String

        defaultConfig {
            if(isAppModule)
                applicationId "com.fashare.mvvm_juejin"

            minSdkVersion _android.minSdkVersion as Integer
            targetSdkVersion _android.targetSdkVersion as Integer
            versionCode _android.versionCode as Integer
            versionName _android.versionName as String
        }

        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

        sourceSets {
            main.java.srcDirs += 'src/main/kotlin'
        }

        if(enableDataBinding){
            dataBinding {
                enabled true
            }
        }
    }

    dependencies {
        // kotlin
        compile _kotlin.kotlin_stdlib
        kapt databindingCompiler

        // rxjava
        compile rx.rxjava2
        compile rx.rxandroid2
    }
}

//apply from: "https://raw.githubusercontent.com/fashare2015/gradle-screen-record/master/screen-record.gradle"
