apply plugin: 'maven-publish'
apply plugin: 'nebula.nebula-bintray-publishing'
apply plugin: 'com.jfrog.artifactory'


tasks.bintrayUpload.dependsOn tasks.check
tasks.artifactoryPublish.dependsOn tasks.check

gradle.taskGraph.whenReady { graph ->
    tasks.bintrayUpload.onlyIf {
        graph.hasTask(':final') || graph.hasTask(':candidate') || graph.hasTask(':devSnapshot')
    }
    tasks.artifactoryPublish.onlyIf {
        graph.hasTask(':snapshot')
    }
}

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

def pomConfig = {
    licenses {
        license {
            name "Apache License, Version 2.0"
            url "http://www.apache.org/licenses/LICENSE-2.0.txt"
            distribution "repo"
        }
    }
    developers {
        developer {
            id "rogeralsing"
            name "Roger Alsing"
            email "rogeralsing@gmail.com"
        }
    }
    scm {
        url "https://github.com/AsynkronIT/protoactor-kotlin"
    }
}

project.extensions.create("artifact", ArtifactExtension)

publishing {
    publications {
        maven(MavenPublication) {
            from components.java
            artifact sourcesJar

            pom.withXml {
                def root = asNode()
                root.appendNode('description', 'Proto.Actor is a Next generation Actor Model framework')
                root.appendNode('name', project.artifact.name)
                root.appendNode('url', 'http://proto.actor')
                root.children().last() + pomConfig
            }
        }
    }
}

bintray {
    dryRun = false
    publish = false

    publications = ['maven']
    pkg {
        repo = 'protoactor-kotlin'
        userOrg = 'asynkronit'
        name = project.name
        desc = project.artifact.description
        websiteUrl = "http://proto.actor/"
        issueTrackerUrl = "https://github.com/AsynkronIT/protoactor-kotlin/issues"
        vcsUrl = "https://github.com/AsynkronIT/protoactor-kotlin.git"
        licenses = ['Apache-2.0']
        labels = ['actor']
        githubRepo = 'AsynkronIT/protoactor-kotlin'
        githubReleaseNotesFile = 'README.md'
    }
}

artifactory {
    publish {
        contextUrl = 'https://oss.jfrog.org'
        repository {
            repoKey = 'oss-snapshot-local'

            if (project.hasProperty('bintrayUser')) {
                username = project.property('bintrayUser')
                password = project.property('bintrayKey')
            }
        }
        defaults {
            publications 'maven'
        }
    }
}

class ArtifactExtension {
    String name = 'Proto.Actor'
    String description = 'Ultra-fast, distributed, cross-platform actors.'
}
