// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.8.0"
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.0.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.22.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

ext {
    // setting release property breaks maven plugin
    // so instead we indicate snapshots with -Psnapshot
    isSnapshot = project.hasProperty('snapshot')
    isSnapCi = System.getenv('SNAP_CI') != null
    isSnapPullRequest = System.getenv('SNAP_PULL_REQUEST_NUMBER') != null
}

/*
 * Gets the version name from the latest Git tag
 */
def getVersionName = {
    version = ""
    def stdout = new ByteArrayOutputStream()
    try {
        exec {
            commandLine 'git', 'describe', '--tags'
            standardOutput = stdout
        }
        version = stdout.toString().trim()
    }
    catch (e) {
        println("Can't get version from git: " + e);
        version = "adhoc"
    }
    version = "${version}${isSnapshot ? "-SNAPSHOT" : ""}"
    return version
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    version = getVersionName()
}

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

if (getGradle().getStartParameter().getTaskRequests().toString().contains("release") ||
        getGradle().getStartParameter().getTaskRequests().toString().contains("mavenPublish") ||
        getGradle().getStartParameter().getTaskRequests().toString().contains("closeAndReleaseRepository")) {
    apply plugin: 'io.codearte.nexus-staging'
}

