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

def LIB_GROUP_ID = 'co.euphony.lib'
def LIB_ARTIFACT_ID = 'euphony'
def LIB_VERSION = '0.8.1.2'

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

artifacts {
    archives androidSourcesJar
}

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                groupId LIB_GROUP_ID
                artifactId LIB_ARTIFACT_ID
                version LIB_VERSION
                artifact("$buildDir/outputs/aar/euphony-release.aar")
                artifact(androidSourcesJar)

                pom {
                    name = LIB_ARTIFACT_ID
                    description = 'Euphony; Acoustic Telecommunication Library'
                    url = 'https://github.com/euphony-io/euphony'

                    licenses {
                        license {
                            name = 'Apache 2.0 License'
                            url = 'https://github.com/euphony-io/euphony/blob/master/LICENSE'
                        }
                    }

                    developers {
                        developer {
                            id = 'designe'
                            name = 'Ji-woong Choi'
                            email = "designe@outlook.com"
                        }
                    }

                    scm {
                        connection = 'scm:git:github.com/euphony-io/euphony.git'
                        developerConnection = "scm:git:ssh://github.com/euphony-io/euphony.git"
                        url = 'https://github.com/euphony-io/euphony/tree/main'
                    }
                }
            }
        }
    }
}

ext["signing.keyId"] = rootProject.ext["signing.keyId"]
ext["signing.password"] = rootProject.ext["signing.password"]
ext["signing.key"] = rootProject.ext["signing.key"]

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