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

group = "com.etebase"
version = "2.3.2"
ext.isSnapshot = version.endsWith("SNAPSHOT")

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    ndkVersion "21.3.6528147"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName version

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"

        multiDexEnabled true
    }


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

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.annotation:annotation:1.1.0'

    def okhttp3Version = "3.12.1"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3Version"

    // Required -- JUnit 4 framework
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test:rules:1.1.0'

    testImplementation 'junit:junit:4.12'
}

afterEvaluate {
    task androidJavadocs(type: Javadoc) {
        source = android.sourceSets.main.java.srcDirs
        classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
        exclude '**/R.html', '**/R.*.html', '**/index.html'
    }

    task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
        archiveClassifier.set('javadoc')
        from androidJavadocs.destinationDir
    }

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

    publishing {
        publications {
            release(MavenPublication) {
                from components.release

                artifact androidJavadocsJar
                artifact androidSourcesJar

                pom {
                    name = "Etebase Android"
                    description = "Etebase API client for Android"
                    url = "https://www.etebase.com"
                    licenses {
                        license {
                            name = "BSD-3-Clause"
                            url = "https://spdx.org/licenses/BSD-3-Clause.html"
                        }
                    }
                    developers {
                        developer {
                            id = "tasn"
                            name = "Tom Hacohen"
                            email = "maven@stosb.com"
                        }
                    }
                    scm {
                        connection = "scm:git:git://github.com/etesync/etesync-java.git"
                        developerConnection = "scm:git:ssh://github.com/etesync/etesync-jvm"
                        url = "https://github.com/etesync/etesync-java"
                    }
                }
            }
        }

        repositories {
            maven {
                def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
                def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
                url = isSnapshot ? snapshotsRepoUrl : releasesRepoUrl
                credentials {
                    username = ossrhUsername
                    password = ossrhPassword
                }
            }
        }
    }

    if (!isSnapshot) {
        signing {
            useGpgCmd()
            sign publishing.publications.release
        }
    }
}
