apply plugin: 'com.android.library'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'kotlin-android'

archivesBaseName = "signal-service-android"
version          = "1.0.0"
group            = "org.session"

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

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

android {
    compileSdkVersion 30
    buildToolsVersion '29.0.3'

    defaultConfig {
        minSdkVersion androidMinSdkVersion
        targetSdkVersion androidCompileSdkVersion
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    libraryVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.aar')) {
                def fileName = "${archivesBaseName}-${version}.aar"
                output.outputFileName = fileName
            }
        }
    }
}

dependencies {
    implementation "androidx.annotation:annotation:1.1.0"

    implementation "com.google.protobuf:protobuf-java:$protobufVersion"
    implementation "com.googlecode.libphonenumber:libphonenumber:8.10.7"
    implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonDatabindVersion"

    implementation "org.whispersystems:curve25519-java:$curve25519Version"
    implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
    implementation "org.threeten:threetenbp:1.3.6"

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

    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
    implementation "nl.komponents.kovenant:kovenant:$kovenantVersion"

    testImplementation "junit:junit:3.8.2"
    testImplementation "org.assertj:assertj-core:1.7.1"
    testImplementation "org.conscrypt:conscrypt-openjdk-uber:2.0.0"
}

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}

def isReleaseBuild() {
    return version.contains("SNAPSHOT") == false
}

def getReleaseRepositoryUrl() {
    return ""
}

def getRepositoryUsername() {
    return ""
}

def getRepositoryPassword() {
    return ""
}

signing {
    required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
    sign configurations.archives
}

uploadArchives {
    configuration = configurations.archives
    repositories.mavenDeployer {
        beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

        repository(url: getReleaseRepositoryUrl()) {
            authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
        }

        pom.project {
            name 'signal-service-android'
            packaging 'aar'
            description 'Signal service communication library for Android'
            url 'https://github.com/loki-project/session-android-service'

            scm {
                url 'scm:git@github.com:loki-project/session-android-service.git'
                connection 'scm:git@github.com:loki-project/session-android-service.git'
                developerConnection 'scm:git@github.com:loki-project/session-android-service.git'
            }

            licenses {
                license {
                    name 'GPLv3'
                    url 'https://www.gnu.org/licenses/gpl-3.0.txt'
                    distribution 'repo'
                }
            }

            developers {
                developer {
                    name 'Niels Andriesse'
                }
            }
        }
    }
}

task installArchives(type: Upload) {
    description "Installs the artifacts to the local Maven repository."
    configuration = configurations['archives']
    repositories {
        mavenDeployer {
            repository url: "file://${System.properties['user.home']}/.m2/repository"
        }
    }
}