apply plugin: 'com.android.library'

android {
    compileSdkVersion 30

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

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

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

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.annotation:annotation:1.2.0'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

// PUBLISH

apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'

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

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

afterEvaluate {
    javadoc.classpath += files(android.libraryVariants.collect { variant ->
        variant.javaCompileProvider.get().classpath.files
    })
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

signing {
    useInMemoryPgpKeys(
            rootProject.ext["signing.keyId"],
            rootProject.ext["signing.key"],
            rootProject.ext["signing.password"],
    )
    sign publishing.publications
}

tasks.withType(Javadoc) {
    options.addStringOption('Xdoclint:none', '-quiet')
    options.addStringOption('encoding', 'UTF-8')
    options.addStringOption('charSet', 'UTF-8')
}

def artifact = new Properties()
artifact.load(new FileInputStream(rootProject.rootDir.getAbsolutePath() + "/deploy.settings"))

version = artifact.version
group = artifact.groupId
archivesBaseName = artifact.id

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                groupId artifact.groupId
                artifactId artifact.id
                version artifact.version
                from components.release

                pom {
                    name = artifact.id
                    packaging = 'aar'
                    description = 'an advanced library which adds emoji,sticker,... support to your Android application.'
                    url = artifact.siteUrl

                    scm {
                        connection = artifact.gitUrl
                        developerConnection = artifact.gitUrl
                        url = artifact.siteUrl
                    }

                    licenses {
                        license {
                            name = 'The Apache License, Version 2.0'
                            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }

                    developers {
                        developer {
                            id = 'Aghajari'
                            name = 'AmirHossein Aghajari'
                            email = 'amirhossein.aghajari.82@gmail.com'
                        }
                    }
                }
            }
        }
    }
}
