plugins {
    id 'com.android.library'
    id 'com.novoda.static-analysis' version '1.2'
    id "com.github.spotbugs" version '3.0.0'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

group = 'com.github.eggheadgames'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion rootProject.ext.general.compileSdkVersion
    buildToolsVersion rootProject.ext.general.buildToolsVersion

    defaultConfig {
        minSdkVersion rootProject.ext.general.minSdkVersion
        targetSdkVersion rootProject.ext.general.targetSdkVersion
        versionCode rootProject.ext.general.versionCode
        versionName rootProject.ext.general.versionName
    }

    flavorDimensions "appstore"
    productFlavors {
        google {
            dimension "appstore"
        }
        amazon {
            dimension "appstore"
        }
    }

    lintOptions {
        warningsAsErrors true
        // ok disables
        disable 'GradleDependency'
        disable 'AllowBackup'
    }
}

dependencies {
    implementation "androidx.core:core-ktx:1.3.1"
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    amazonApi files('libs/in-app-purchasing-2.0.76.jar')

    googleApi 'com.android.billingclient:billing:3.0.0'

    testImplementation 'junit:junit:4.13'
    testImplementation 'org.mockito:mockito-core:2.24.0'
}

staticAnalysis {
    penalty {
        maxErrors = 0
        maxWarnings = 0
    }
    pmd {
        ignoreFailures = false
        reportsDir = file("$project.buildDir/outputs/")
    }
    spotbugs {
        ignoreFailures = false
        reportsDir = file("$project.buildDir/outputs/")
        reportLevel = "medium"
        effort = "max"

        excludeFilter rootProject.file('library/findbugs_excludes.xml')
    }
}

// the following code is used to force jitpack to build different builds for each flavour.
// If you change it, please make sure that it builds correctly, since billing library is used on the all Eggheadgames apps.
// START JITPACK ARTIFACTS CONFIG
task sourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.javaDirectories
}

artifacts {
    archives sourcesJar
}

if (android.productFlavors.size() > 0) {
    android.libraryVariants.all { variant ->
        if (variant.name.toLowerCase().contains("debug")) {
            return
        }

        def bundleTask = tasks["bundle${variant.name.capitalize()}Aar"]

        artifacts {
            archives(bundleTask.archivePath) {
                classifier variant.flavorName
                builtBy bundleTask
                name = project.name
            }
        }
    }
}
// END JITPACK ARTIFACTS CONFIG