apply plugin: 'signing'
apply plugin: 'digital.wup.android-maven-publish'

def isAndroid = plugins.hasPlugin('com.android.library')

ext {
    pomFile = file("${project.buildDir}/generated-pom.xml")
    isReleaseVersion = !(project.version =~ /-SNAPSHOT$/)
}

if (isAndroid) {
    task javadoc(type: Javadoc) {
        source = android.sourceSets.main.java.srcDirs
    }
}

task javadocsJar(type: Jar) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}
task sourcesJar(type: Jar) {
    classifier = 'sources'
    if (isAndroid) {
        from android.sourceSets.main.java.srcDirs
    } else {
        from sourceSets.main.allSource
    }
}

def siteUrl = 'https://github.com/evant/redux'
def gitUrl = 'https://github.com/evant/redux.git'

publishing {
    repositories {
        maven {
            if (project.ext.isReleaseVersion) {
                url 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
            } else {
                url 'https://oss.sonatype.org/content/repositories/snapshots/'
            }

            credentials {
                username = project.findProperty('sonatype.username')
                password = project.findProperty('sonatype.password')
            }
        }
    }

    publications {
        lib(MavenPublication) {
            if (isAndroid) {
                from components.android
            } else {
                from components.java
            }

            artifact sourcesJar
            artifact javadocsJar

            pom {
                name = project.name
                description = 'Redux ported to java/android'
                url = siteUrl

                scm {
                    url = siteUrl
                    connection = gitUrl
                    developerConnection = gitUrl
                }

                licenses {
                    license {
                        name = 'The Apache Software License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution = 'repo'
                    }
                }

                developers {
                    developer {
                        id = 'evant'
                        name = 'Evan Tatarka'
                    }
                }
            }
        }
    }
}

if (project.ext.isReleaseVersion) {
    signing {
        sign publishing.publications.lib
    }
}
