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

Properties localProps = new Properties()
File localProperties = new File(rootProject.rootDir, "local.properties")
if (localProperties.exists() && localProperties.isFile()) {
    localProperties.withInputStream { localProps.load(it) }
}

project.ext["signing.keyId"] = localProps.getProperty("signing.keyId")
project.ext["signing.secretKeyRingFile"] = localProps.getProperty("signing.secretKeyRingFile")
project.ext["signing.password"] = localProps.getProperty("signing.password")

java {
    withJavadocJar()
    withSourcesJar()
}

afterEvaluate {
    publishing {
        publications {
            releaseJar(MavenPublication) {
                from components.java

                groupId = 'com.github.kirich1409'
                artifactId = project.ext.artifactId
                version = rootProject.ext.versionName

                pom {
                    name = 'Strict Mode Compat'
                    description = 'Android Strict Mode Compat'
                    url = 'https://github.com/kirich1409/StrictModeCompat'
                    licenses {
                        license {
                            name = 'The Apache License, Version 2.0'
                            url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
                        }
                    }
                    developers {
                        developer {
                            id = 'kirich1409'
                            name = 'Kirill Rozov'
                            email = 'krl.rozov@gmail.com'
                        }
                    }
                    scm {
                        url = 'https://github.com/kirich1409/StrictModeCompat.git'
                    }
                }
            }
        }

        repositories {
            maven {
                name = "sonatypeStaging"
                url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
                credentials {
                    username = localProps.getProperty("ossrhUsername")
                    password = localProps.getProperty("ossrhPassword")
                }
            }

            maven {
                name = "sonatypeSnapshots"
                url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
                credentials {
                    username = localProps.getProperty("ossrhUsername")
                    password = localProps.getProperty("ossrhPassword")
                }
            }
        }
    }

    signing {
        sign(publishing.publications)
    }
}
