import com.lesfurets.gradle.versions.*
import com.lesfurets.gradle.git.*

apply from: 'dependencyVersions.gradle'

allprojects {
    group = 'io.doov'
    version = "1.0-SNAPSHOT"
}

repositories {
    mavenCentral()
}

apply plugin: VersionsPlugin
apply plugin: 'jacoco'

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

subprojects {

    repositories {
        mavenCentral()
    }

    apply plugin: 'java'
    apply plugin: 'java-library'
    apply plugin: 'idea'
    apply plugin: 'eclipse'
    apply plugin: 'signing'
    apply plugin: 'jacoco'

    dependencies {
        testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion
        testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junitJupiterVersion
        testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitJupiterVersion
        testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: junitPlatformLauncherVersion
    }

    compileJava {
        sourceCompatibility = '11'
        targetCompatibility = '11'
    }

    javadoc {
        source = sourceSets.main.allJava
        // options.outputLevel = 'QUIET'
        options.addStringOption('Xdoclint:none', '-quiet')
    }

    test {
        useJUnitPlatform()
        testLogging {
            events "failed"
            exceptionFormat "full"
        }
    }

    jacoco {
        toolVersion = "0.8.7"
    }
    
    check.dependsOn(jacocoTestReport)

    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
        options.compilerArgs << '-proc:none'
    }

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

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

    artifacts {
        archives javadocJar, sourcesJar
    }

    signing {
        required { gradle.taskGraph.hasTask("uploadArchives") }
        sign configurations.archives
    }

    def pomProject = {
        description = 'dOOv, a fluent API for type-safe domain model validation'
        url = 'https://www.dOOv.org'
        scm {
            url 'https://github.com/lesfurets/dOOv'
            connection 'scm:git:git://github.com/lesfurets/dOOv.git'
            developerConnection 'scm:git:git@github.com/lesfurets/dOOv.git'
        }
        licenses {
            license {
                name 'The Apache Software License, Version 2.0'
                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                distribution 'repo'
            }
        }
        developers {
            developer {
                name 'Alexandre Dubreuil'
            }
            developer {
                name 'Gilles DiGuglielmo'
            }
            developer {
                name 'Ozan Gunalp'
            }
        }
    }
}

task codeCoverageReport(type: JacocoReport) {
    executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec")

    subprojects.each {
        sourceSets it.sourceSets.main
    }

    reports {
        xml.destination file("$buildDir/reports/jacoco/codeCoverageReport/jacocoCoverageReport.xml")
        html.destination file("$buildDir/reports/jacoco/codeCoverageReport/html")
    }
}

codeCoverageReport.dependsOn {
    subprojects*.check
}

wrapper {
    gradleVersion = '6.8.1'
    distributionType = Wrapper.DistributionType.ALL
}