buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven { // add this to use snapshots
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
    }
}

apply plugin: 'com.android.library'
apply plugin: "kotlin-android"

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
    buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
    compileSdkVersion safeExtGet('compileSdkVersion', 28)

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 16)
        targetSdkVersion safeExtGet('targetSdkVersion', 28)
        versionCode 1
        versionName '7.0.0'
        consumerProguardFiles 'proguard-rules.pro'
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        abortOnError true
        warningsAsErrors true
        baseline file("lint-baseline.xml")
    }
}

dependencies {
    api "com.bugsnag:bugsnag-android:5.9.1"
    api "com.bugsnag:bugsnag-plugin-react-native:5.9.1"
    implementation 'com.facebook.react:react-native:+'

    testImplementation "junit:junit:4.12"
    testImplementation "org.mockito:mockito-core:2.28.2"
}

// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// once released, it should look in the node_modules at the root of the project.
//
// In development, we need to edit this to look at the top-level node_modules of
// the monorepo instead.
def facebookRepo = "$rootDir/../node_modules/react-native/android"

// A copy of bugsnag-android AAR artefacts are stored in @bugsnag/react-native/android,
// as part of a local maven repository. This adds the repository as a source of
// dependencies that Gradle can resolve.
def bugsnagRepo = "$rootDir/../node_modules/@bugsnag/react-native/android"

if (safeExtGet("bugsnagdev", false)) {
    project.logger.lifecycle("Development mode enabled, searching for dependencies at top of monorepo.")
    facebookRepo = "$rootDir/../../../node_modules/react-native/android"
    bugsnagRepo = "$rootDir"
}

allprojects {
    repositories {
        maven { url facebookRepo }
        maven { url bugsnagRepo }
        jcenter()
        google()
    }
}

apply plugin: 'checkstyle'

checkstyle {
    toolVersion = "8.18"
}

task("checkstyle", type: Checkstyle) {
    configFile rootProject.file("config/checkstyle/checkstyle.xml")
    source  "src/"
    include "**/*.java"
    exclude "**/external/**/*.java"
    classpath = files()
}
