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

group = 'me.tatarka.injectedvmprovider'
version = '3.0.0'

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

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    failOnError = false
}

task javadocsJar(type: Jar) {
    classifier = 'javadoc'
    from(androidJavadocs)
}

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

publishing {
    publications {
        lib(MavenPublication) {
            from components.android
            artifact sourcesJar
            artifact javadocsJar

            pom {
                name = project.name
                description = 'Small lib to use easily use Android\'s ViewModels with a depedency injection framework like dagger'
                url = siteUrl
                scm {
                    connection = gitUrl
                    developerConnection = gitUrl
                    url = siteUrl
                }
                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id = 'evant'
                        name = 'Evan Tatarka'
                    }
                }
            }
        }
    }
    repositories {
        maven {
            def releasesRepoUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
            def snapshotsRepoUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
            credentials {
                username project.findProperty('sonatype.username')
                password project.findProperty('sonatype.password')
            }
        }
    }
}

if (project.hasProperty("signing.keyId")) {
    signing {
        sign publishing.publications.lib
    }
}
