apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

def description = "Provides Kotlin Coroutines suspendable await() extensions for okhttp3.Call"
def githubId = "gildor/kotlin-coroutines-okhttp"
def repoWeb = "https://github.com/${githubId}"
def repoVcs = "${repoWeb}.git"
def issueTracker = "${repoWeb}/issues"
def tags = ['okhttp', 'kotlin', 'coroutines']
def licenseId = "Apache-2.0"
def licenseName = "The Apache Software License, Version 2.0"
def licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0.txt"
def releaseTag = "v${project.version}"

// Create the pom configuration:
def pomConfig = {
    developers {
        developer {
            name "Andrey Mischenko"
            email "git@gildor.ru"
            organizationUrl "https://github.com/gildor"
        }
    }
    scm {
        url repoWeb
        connection "scm:git:${repoVcs}"
        developerConnection "scm:git:${repoVcs}"
        tag releaseTag
    }
    issueManagement {
        system "GitHub Issues"
        url issueTracker
    }
    licenses {
        license {
            name licenseName
            url licenseUrl
        }
    }
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

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

publishing {
    publications {
        Publication(MavenPublication) {
            from components.java
            artifact sourcesJar
            artifact javadocJar
            pom.withXml {
                def root = asNode()
                root.appendNode('name', project.name)
                root.appendNode('description', description)
                root.appendNode('url', repoWeb)
                root.children().last() + pomConfig
            }
        }
    }
}

bintray {
    user = project.properties['bintray.user']
    key = project.properties['bintray.key']
    publications = ['Publication']
    pkg {
        repo = project.properties['bintray.repo'] ?: 'maven'
        name = project.name
        desc = description
        githubRepo = githubId
        githubReleaseNotesFile = 'CHANGELOG.md'
        websiteUrl = repoWeb
        issueTrackerUrl = "${repoWeb}/issues"
        vcsUrl = repoVcs
        licenses = [licenseId]
        labels = tags
        version {
            name = project.version
            vcsTag = releaseTag
        }
    }
}
