/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

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

buildscript {
    ext.kotlin_version = '1.9.10'
    ext.jacocoVersion = '0.8.8'

    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.6.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.3.1"
        classpath("org.jlleitschuh.gradle:ktlint-gradle:9.1.1")
        classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.2'
        classpath('org.ow2.asm:asm:9.7')
    }
}
plugins {
    id "io.gitlab.arturbosch.detekt" version "1.3.1"
    id "org.jlleitschuh.gradle.ktlint" version "9.1.1"
    id 'org.jetbrains.dokka' version '1.9.20'
}

dokkaHtmlMultiModule {
    outputDirectory = file("$rootDir/docs")
}

apply plugin: 'io.gitlab.arturbosch.detekt'
apply plugin: 'org.jlleitschuh.gradle.ktlint'

def localPropertiesFile = new File(getRootDir(), "local.properties")
Properties localProperties = new Properties()
if (localPropertiesFile.exists()) {
    localPropertiesFile.withInputStream { instr ->
        localProperties.load(instr)
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
        flatDir {
            dirs '../amazon-chime-sdk/libs'
        }
    }
    project.ext {
        chimeMinSdkVersion = 21
        chimeTargetSdkVersion = 35
        chimeCompileSdkVersion = 35
        sdkDir = localProperties.getProperty('sdk.dir')
        ndkDir = localProperties.getProperty('ndk.dir')
    }
}

subprojects {
    apply plugin: "org.jlleitschuh.gradle.ktlint"
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

task installGitHook(type: Copy) {
    from new File(rootProject.rootDir, 'pre-commit')
    into { new File(rootProject.rootDir, '.git/hooks') }
    fileMode 0744
}

tasks.withType(Test) {
    exclude '**/DefaultActiveSpeakerDetectorTest'
}

tasks.getByPath(':app:preBuild').dependsOn installGitHook
