/**
 * Script for publishing the module
 * Source: https://getstream.io/blog/publishing-libraries-to-mavencentral-2021
 *
 *
 */

apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'org.jetbrains.dokka'

task androidSourcesJar(type: Jar) {
    archiveClassifier.set('sources')
    if (project.plugins.findPlugin("com.android.library")) {
        // For Android libraries
        from android.sourceSets.main.java.srcDirs
        //from android.sourceSets.main.kotlin.srcDirs
    } else {
        // For pure Kotlin libraries, in case you have them
        from sourceSets.main.java.srcDirs
        from sourceSets.main.kotlin.srcDirs
    }
}

tasks.withType(dokkaHtmlPartial.getClass()).configureEach {
    pluginsMapConfiguration.set(
            ["org.jetbrains.dokka.base.DokkaBase": """{ "separateInheritedMembers": true}"""]
    )
}

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

artifacts {
    archives androidSourcesJar
    archives javadocJar
}

group = rootProject.group
version = rootProject.version

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                // The coordinates of the library
                groupId group
                artifactId 'simpledialogfragments'
                version version

                // Artifacts
                from components.release

                // Metadata
                pom {
                    name = 'SimpleDialogFragments'
                    description = 'A collection of easy to use and extendable DialogFragment\'s for Android'
                    url = 'https://github.com/eltos/SimpleDialogFragments'
                    developers {
                        developer {
                            id = 'eltos'
                            name = 'Philipp Niedermayer'
                            email = 'eltos@outlook.de'
                        }
                    }
                    licenses {
                        license {
                            name = 'The Apache Software License, Version 2.0'
                            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }

                    // Version control info
                    scm {
                        connection = 'scm:git:github.com/eltos/SimpleDialogFragments.git'
                        developerConnection = 'scm:git:ssh://github.com/eltos/SimpleDialogFragments.git'
                        url = 'https://github.com/eltos/SimpleDialogFragments'
                    }
                }
            }
        }
    }
}

// Signing
ext["signing.keyId"] = rootProject.ext["signing.keyId"]
ext["signing.password"] = rootProject.ext["signing.password"]
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]
signing {
    if (project.ext["signing.password"]?.trim()) { // sign only if we have the password
        sign publishing.publications
    }
}