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

android {
    compileSdkVersion rootProject.ext.android.compileSdkVersion
    buildToolsVersion rootProject.ext.android.buildToolsVersion

    defaultConfig {
        minSdkVersion rootProject.ext.android.minSdkVersion
        targetSdkVersion rootProject.ext.android.targetSdkVersion
        versionCode rootProject.ext.android.versionCode
        versionName rootProject.ext.android.versionName
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compileOnly project(':core')
    compileOnly rootProject.ext.libs.recyclerview
}


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

task javadoc(type: Javadoc) {
    failOnError false
    options.encoding = 'UTF-8'
    source = android.sourceSets.main.java.sourceFiles
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += configurations.compile
}

// build a jar with javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
    archiveClassifier.set('javadoc')
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

install {
    repositories.mavenInstaller {
        pom {
            project {
                packaging 'aar'
                name 'SmoothRefreshLayout-ClassicKit'
                groupId rootProject.ext.bintray['groupId']
                url rootProject.ext.bintray['siteUrl']
                version rootProject.ext.bintray['libVersion']
                artifactId 'srl-ext-classics'
                description 'Classic style view kit for SmoothRefreshLayout'
                licenses {
                    license {
                        name rootProject.ext.bintray['licenseName']
                        url rootProject.ext.bintray['licenseUrl']
                    }
                }
                developers {
                    developer {
                        id rootProject.ext.bintray['developerId']
                        name rootProject.ext.bintray['developerName']
                        email rootProject.ext.bintray['developerEmail']
                    }
                }
                scm {
                    connection rootProject.ext.bintray['gitUrl']
                    developerConnection rootProject.ext.bintray['gitUrl']
                    url rootProject.ext.bintray['siteUrl']
                }
            }
        }
    }
}

signing {
    sign publishing.publications
}

publishing {
    publications {
        release(MavenPublication) {
            groupId rootProject.ext.bintray['groupId']
            artifactId 'srl-ext-classics'
            version rootProject.ext.bintray['libVersion']

            artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
            artifact sourcesJar
            artifact javadocJar

            pom {
                name = 'srl-ext-classics'
                description = 'Classic style view kit for SmoothRefreshLayout'
                url = rootProject.ext.bintray['siteUrl']
                licenses {
                    license {
                        name = rootProject.ext.bintray['licenseName']
                        url = rootProject.ext.bintray['licenseUrl']
                    }
                }
                developers {
                    developer {
                        id = rootProject.ext.bintray['developerId']
                        name = rootProject.ext.bintray['developerName']
                        email = rootProject.ext.bintray['developerEmail']
                    }
                }
                scm {
                    connection = rootProject.ext.bintray['gitUrl']
                    developerConnection = rootProject.ext.bintray['gitUrl']
                    url = rootProject.ext.bintray['siteUrl']
                }
                withXml {
                    def dependenciesNode = asNode().appendNode('dependencies')

                    project.configurations.implementation.allDependencies.each {
                        def dependencyNode = dependenciesNode.appendNode('dependency')
                        dependencyNode.appendNode('groupId', it.group)
                        dependencyNode.appendNode('artifactId', it.name)
                        dependencyNode.appendNode('version', it.version)
                    }
                }
            }
        }
    }
    repositories {
        maven {
            name = "sonatype"
            url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
            credentials {
                Properties properties = new Properties()
                properties.load(project.rootProject.file('local.properties').newDataInputStream())
                username = properties.getProperty("bintray.user")
                password = properties.getProperty("bintray.key")
            }
        }
    }
}