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

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

artifacts {
    archives javadocJar
    archives sourcesJar
}

apply plugin: 'maven'
apply plugin: 'signing'

group = 'com.arthenica'
archivesBaseName = releaseProject
version = releaseVersionName

File propertiesFile = project.rootProject.file('local.properties')
if (propertiesFile.exists()) {
    Properties properties = new Properties()
    properties.load(new FileInputStream(propertiesFile))
    properties.each { name, value ->
        ext[name] = value
    }
}

ext {
    publishedGroupId = group
    artifact = releaseProject
    libraryName = releaseProject
    libraryVersion = version
    libraryDescription = releaseProjectDescription

    siteUrl = 'https://github.com/tanersener/ffmpeg-kit'
    gitUrl = 'https://github.com/tanersener/ffmpeg-kit.git'

    developerId = 'tanersener'
    developerName = 'Taner Sener'
    developerEmail = 'tanersener@gmail.com'

    if (Project.hasProperty('releaseGPL')) {
        licenseName = 'GNU General Public License version 3'
        licenseUrl = 'https://www.gnu.org/licenses/gpl-3.0.txt'
    } else {
        licenseName = 'GNU Lesser General Public License, Version 3'
        licenseUrl = 'https://www.gnu.org/licenses/lgpl-3.0.txt'
    }
}

uploadArchives {
    repositories {
        mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: ossrhUsername, password: ossrhPassword)
            }

            snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                authentication(userName: ossrhUsername, password: ossrhPassword)
            }

            pom.project {
                packaging 'aar'
                name = libraryName
                description = libraryDescription
                url = siteUrl

                licenses {
                    license {
                        name = licenseName
                        url = licenseUrl
                    }
                }
                developers {
                    developer {
                        id developerId
                        name developerName
                        email developerEmail
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}

signing {
    sign configurations.archives
}
