buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
    }
}

plugins {
    id "com.github.hierynomus.license" version "0.12.1"
}

allprojects {
    group = "io.eventuate.client.java"
}

projects {

    license {
        header rootProject.file('src/license/HEADER')
    }
}


allprojects {
    apply plugin: 'java'
    apply plugin: 'maven'
    apply plugin: 'com.jfrog.bintray'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    bintray {
        publish = true
        user = System.getenv('BINTRAY_USER')
        key = System.getenv('BINTRAY_KEY')
        configurations = ['archives']
        pkg {
            repo = "eventuate-maven-$bintrayRepoType"
            name = 'eventuate-client-java'
            licenses = ['Apache-2.0']
            vcsUrl = 'https://github.com/eventuate-clients/eventuate-client-java'
        }
    }

    repositories {
        mavenCentral()
        maven { url "http://mavenrepo.eventuate.io/release"}
        eventuateMavenRepoUrl.split(',').each { repoUrl -> maven { url repoUrl } }
    }

    dependencies {
        testCompile "junit:junit:4.12"
    }

    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: deployUrl)
                pom.project {
                    licenses {
                        license {
                            name 'The Apache Software License, Version 2.0'
                            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                            distribution 'repo'
                        }
                    }
                }
            }
        }
    }
}

gradle.projectsEvaluated {
    task aggregateJavaDocs(type: Javadoc) {
        description = 'Aggregated Javadoc API documentation of all subprojects.'
        group = JavaBasePlugin.DOCUMENTATION_GROUP
        dependsOn subprojects.findAll { subproject -> subproject.plugins.hasPlugin(PublicModulePlugin) }.javadoc

        source subprojects.findAll { subproject -> subproject.plugins.hasPlugin(PublicModulePlugin) }.javadoc.source
        destinationDir file("$buildDir/docs/javadoc")
        classpath = files(subprojects.findAll { subproject -> subproject.plugins.hasPlugin(PublicModulePlugin) }.javadoc.classpath)
    }

    task("aggregateJavaDocsJar", type: org.gradle.api.tasks.bundling.Jar, dependsOn: project.aggregateJavaDocs) {
        classifier = 'javadoc'
        from 'build/docs/javadoc'
    }

    artifacts {
        archives project.aggregateJavaDocsJar
    }

}
