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

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    archiveClassifier = '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) {
    archiveClassifier = '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')
}

File deploy = project.rootProject.file("maven/deploy.settings")
def artifact = new Properties()
artifact.load(new FileInputStream(deploy))

version = artifact.version
group = artifact.groupId

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

                pom {
                    name = artifact.id
                    packaging = 'aar'
                    description = artifact.description
                    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'
                        }
                    }
                }
            }
        }
    }
}