apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'
android {
    compileSdkVersion 26

    defaultConfig {

        minSdkVersion 23
        targetSdkVersion 26
        
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation 'co.nstant.in:cbor:0.8'
    implementation ('com.amazonaws:aws-android-sdk-iot:2.13.5')

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    testImplementation 'junit:junit:4.12'
    compileOnly 'org.projectlombok:lombok:1.18.4'
    annotationProcessor 'org.projectlombok:lombok:1.18.4'
}

task androidJavaDocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    destinationDir = file("../docs/")
    failOnError false
}

task androidJavaDocsJar(type: Jar, dependsOn: androidJavaDocs) {
    archiveClassifier = 'javadoc'
    from tasks.androidJavaDocs.destinationDir
}

task androidSourcesJar(type: Jar) {
    archiveClassifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

task copyLibs(type: Copy) {
    from configurations.implementation
    into 'libs'
}

configurations {
    archives {
        extendsFrom configurations.default
    }
}

publishing {
    publications {
        pluginPublication(MavenPublication) {
            groupId publishedGroupId
            artifactId artifact
            version = versionNumber
            artifact androidJavaDocsJar
            artifact androidSourcesJar

            pom {
                packaging = "aar"
                name = libraryName
                description = libraryDescription
                groupId = publishedGroupId
                artifactId = artifact
                url = siteUrl

                licenses {
                    license {
                        name = licenseName
                        url = licenseUrl
                        distribution = "repo"
                    }
                }
                developers {
                    developer {
                        id = developerId
                        name = developerName
                        email = developerEmail
                    }
                }
                scm {
                    connection = gitUrl
                    developerConnection = gitUrl
                    url = gitUrl
                }
            }

            afterEvaluate {
                from components.release
            }
        }
    }

    repositories {

        maven {

            def stagingRepoUrl = "https://aws.oss.sonatype.org/service/local/staging/deploy/maven2/"
            def snapshotsRepoUrl = "https://aws.oss.sonatype.org/content/repositories/snapshots/"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : stagingRepoUrl

            credentials {
                username ossrhUsername
                password ossrhPassword

            }
        }
    }
}
signing {
    sign configurations.archives
    sign publishing.publications.pluginPublication
}