// Copyright 2017-2020 Fitbit, Inc
// SPDX-License-Identifier: Apache-2.0

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'com.jfrog.artifactory'
    id 'maven-publish'
}

apply from: '../jacoco.gradle'

def packageName = 'com.fitbit.remoteapi'

apply from: '../gg_lib_android_build.gradle'

dependencies {
    implementation project(':RxFitbitGatt')
    implementation project(':GoldenGateBindings')
    implementation project(':GoldenGateConnectionManager')
    implementation project(':linkcontroller')
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    // api as cbor is part of external interface
    api "co.nstant.in:cbor:$CBOR_VERSION"

    implementation "com.github.fitbit:bitgatt:$BITGATT_COMMIT_VERSION"
    implementation "androidx.appcompat:appcompat:$ANDROIDX_APPCOMPAT_VERSION"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
    implementation "io.reactivex.rxjava2:rxjava:$RXJAVA_VERSION"
    implementation "io.reactivex.rxjava2:rxandroid:$RXANDROID_VERSION"
    implementation "com.jakewharton.timber:timber:$TIMBER_VERSION"
    implementation "com.google.android.material:material:$ANDROID_MATERIAL_VERSION"

    testImplementation "junit:junit:$JUNIT_VERSION"
    testImplementation "org.jetbrains.kotlin:kotlin-test:$KOTLIN_VERSION"
    testImplementation "org.mockito:mockito-core:$MOCKITO_VERSION"
    testImplementation "org.mockito.kotlin:mockito-kotlin:$MOCKITO_KOTLIN_VERSION"
}

task sourceJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier "sources"
}

publishing {
    publications {
        aar(MavenPublication) {
            groupId packageName
            version = libraryVersionName
            artifactId project.getName()

            artifact sourceJar
            artifact ("$buildDir/outputs/aar/remoteapi-${publishVariant}.aar")
        }
    }
}

switch(publishVariant) {
    case "release":
        //Skip publishing a remoteAPI library when publishing a release build. Remote API is only used for internal users.
        artifactoryPublish.skip = true
        artifactoryPublish.dependsOn ('assembleRelease')
        break
    default:
        artifactoryPublish.dependsOn ('assembleLibrary')
        break
}
