buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.owasp:dependency-check-gradle:6.5.0.1")
    }
}

subprojects {
    apply(plugin = "java-library")
    apply(plugin = "org.owasp.dependencycheck")

    group = "eu.jonahbauer"
    version = "1.0-SNAPSHOT"

    val implementation by configurations
    val testImplementation by configurations
    val compileOnly by configurations
    val annotationProcessor by configurations
    val testCompileOnly by configurations
    val testAnnotationProcessor by configurations
    val runtimeOnly by configurations

    repositories {
        mavenCentral()
    }

    dependencies {
        implementation(Annotations.id)

        implementation(Log4j2.api)
        runtimeOnly(Log4j2.core)
        runtimeOnly(Log4j2.slf4j)

        testImplementation(JUnit.jupiter)
        testImplementation(JUnit.jupiter_engine)
        testImplementation(Mockito.inline)
        testImplementation(Mockito.jupiter)

        compileOnly(Lombok.id)
        annotationProcessor(Lombok.id)

        testCompileOnly(Lombok.id)
        testAnnotationProcessor(Lombok.id)
    }

    tasks {
        withType<JavaCompile> {
            sourceCompatibility = "17"
            targetCompatibility = "17"
            options.encoding = "UTF-8"
        }

        withType<Jar> {
            onlyIf {
                !project.the<SourceSetContainer>()["main"].allSource.isEmpty
            }
        }

        named<Test>("test") {
            useJUnitPlatform()
        }

        named("check") {
            dependsOn("dependencyCheckAnalyze")
        }
    }

    configure<org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension> {
        format = org.owasp.dependencycheck.reporting.ReportGenerator.Format.JUNIT
    }
}