buildscript {
    ext {
        gradlePluginVersion = '3.4.2'
        kotlinVersion = '1.3.11'
        supportLibVersion = '28.0.0'
        tagSoupVersion = '1.2.1'
        glideVersion = '3.7.0'
        picassoVersion = '2.5.2'
        robolectricVersion = '3.5.1'
        jUnitVersion = '4.12'
        jSoupVersion = '1.10.3'
        wordpressUtilsVersion = '1.22'
        espressoVersion = '3.0.1'

        aztecVersion = 'v1.3.38'
    }

    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:$gradlePluginVersion"
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'com.github.dcendents.android-maven'

// import the `readReactNativeVersion()` function
apply from: 'https://gist.githubusercontent.com/hypest/742448b9588b3a0aa580a5e80ae95bdf/raw/8eb62d40ee7a5104d2fcaeff21ce6f29bd93b054/readReactNativeVersion.gradle'

group='com.github.wordpress-mobile.gutenberg-mobile'

// fallback flag value for when lib is compiled individually (e.g. via jitpack)
project.ext.buildGutenbergFromSource = false

// The sample build uses multiple directories to
// keep boilerplate and common code separate from
// the main sample code.
List<String> dirs = [
        'main',     // main sample code; look here for the interesting stuff.
        'common',   // components that are reused by multiple samples
        'template'] // boilerplate code that is generated by the sample template process

android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    sourceSets {
        main {
            dirs.each { dir ->
                java.srcDirs "src/${dir}/java"
                java.srcDirs += "src/${dir}/kotlin"
                res.srcDirs "src/${dir}/res"
            }
        }

        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']
    }

    lintOptions {
        disable 'GradleCompatible'
    }
}

repositories {
    jcenter()
    google()

    maven { url "https://jitpack.io" }

    if (!rootProject.ext.buildGutenbergFromSource) {
         // if not building from source (where the node_modules dir is used), use a remote RN maven repo
         def reactNativeRepo = 'https://dl.bintray.com/wordpress-mobile/react-native-mirror/'
         println "Will use the RN maven repo at ${reactNativeRepo}"
         maven { url reactNativeRepo }
     }
}

dependencies {
    api ("com.github.wordpress-mobile.WordPress-Aztec-Android:aztec:$aztecVersion")
    api ("com.github.wordpress-mobile.WordPress-Aztec-Android:wordpress-shortcodes:$aztecVersion")
    api ("com.github.wordpress-mobile.WordPress-Aztec-Android:wordpress-comments:$aztecVersion")
    api ("com.github.wordpress-mobile.WordPress-Aztec-Android:glide-loader:$aztecVersion")
    api "org.wordpress:utils:$wordpressUtilsVersion"

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"

    implementation 'androidx.appcompat:appcompat:1.0.0'

    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'

    if (rootProject.ext.buildGutenbergFromSource) {
        implementation "com.facebook.react:react-native:+" // From node_modules.
    } else {

        // FIXME Temporary fix to get Jitpack builds to green while I work on a solution without hardcoded values.
        //def rnVersion = readReactNativeVersion('../package.json', 'peerDependencies')
        def rnVersion = '0.61.5'
        implementation "com.facebook.react:react-native:${rnVersion}" // From Maven repo
    }
}
