buildscript {
    repositories { jcenter() }

    dependencies {
        classpath 'com.netflix.nebula:gradle-aggregate-javadocs-plugin:2.2.+'
    }
}

//apply plugin: 'nebula-aggregate-javadocs'

Project rootProject = project.rootProject
rootProject.gradle.projectsEvaluated {
    Set<Project> javaSubprojects = rootProject.subprojects.findAll { subproject -> subproject.plugins.hasPlugin(JavaPlugin) }
    if (!javaSubprojects.isEmpty()) {
        rootProject.task("aggregateJavadocs", type: Javadoc) {
            title = '<h1>Reveno Framework </h1>'
            options.bottom = '<i>Copyright &#169; 2019 Artem Dmitriev. All Rights Reserved.</i>'
            description = 'Aggregates Javadoc API documentation of all subprojects.'
            group = JavaBasePlugin.DOCUMENTATION_GROUP
            dependsOn javaSubprojects.javadoc

            source javaSubprojects.javadoc.source
            destinationDir rootProject.file("$rootProject.buildDir/docs/javadoc")
            classpath = rootProject.files(javaSubprojects.javadoc.classpath)
        }
    }
}

allprojects {
    apply plugin: "java"
    apply plugin: "idea"

    group = 'org.reveno'

    repositories {
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        compile "org.slf4j:slf4j-api:$slf4jVersion"
        compile "org.slf4j:slf4j-log4j12:$log4jVersion"

        testCompile "com.google.guava:guava:$guavaVersion"
        testCompile "junit:junit:$junitVersion"
        testCompile "org.easymock:easymock:$easymockVersion"
    }

    def forks = Math.max(1, (int) (Runtime.runtime.availableProcessors()))

    test {
        minHeapSize = "256m"
        maxHeapSize = "256m"
        maxParallelForks = forks
        forkEvery = 1
        systemProperty 'protostuff.runtime.collection_schema_on_repeated_fields', 'true'

        testLogging {
            showExceptions = true
            showCauses = true
            showStackTraces = true
            events "passed", "skipped", "failed", "standardOut", "standardError"
        }
    }

    tasks.withType(Javadoc) {
        options.addStringOption('Xdoclint:none', '-quiet')
        options.setMemberLevel(JavadocMemberLevel.PUBLIC)
    }

    javadoc {
        title = '<h1>Reveno Framework </h1>'

        options.bottom = '<i>Copyright &#169; 2019 Artem Dmitriev. All Rights Reserved.</i>'
        options.addStringOption('XDignore.symbol.file', '-quiet')
        include '**/api/**'
        include '**/commons/**'
        include '**/core/**'
        include '**/utils/**'
        include '**/metrics/**'
        exclude '**/acceptance/**'
        exclude '**/test/**'
    }

    defaultTasks 'clean', 'build'
}
