plugins {
    `java-library`
    `maven-publish`
    pmd
    checkstyle
    jacoco
}

group = "com.knecon.fforesight"

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17

tasks.pmdMain {
    pmd.ruleSetFiles = files("${rootDir}/config/pmd/pmd.xml")
}

tasks.pmdTest {
    pmd.ruleSetFiles = files("${rootDir}/config/pmd/test_pmd.xml")
}

tasks.named<Test>("test") {
    useJUnitPlatform()
    reports {
        junitXml.outputLocation.set(layout.buildDirectory.dir("reports/junit"))
    }
    minHeapSize = "512m"
    maxHeapSize = "2048m"
}

tasks.test {
    finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}

tasks.jacocoTestReport {
    dependsOn(tasks.test) // tests are required to run before generating the report
    reports {
        xml.required.set(true)
        csv.required.set(false)
        html.outputLocation.set(layout.buildDirectory.dir("jacocoHtml"))
    }
}

allprojects {
    publishing {
        publications {
            create<MavenPublication>(name) {
                from(components["java"])
            }
        }
        repositories {
            maven {
                url = uri("https://nexus.knecon.com/repository/red-platform-releases/")
                credentials {
                    username = providers.gradleProperty("mavenUser").getOrNull();
                    password = providers.gradleProperty("mavenPassword").getOrNull();
                }
            }
        }
    }
}

java {
    withJavadocJar()
}

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url = uri("https://nexus.knecon.com/repository/gindev/")
        credentials {
            username = providers.gradleProperty("mavenUser").getOrNull();
            password = providers.gradleProperty("mavenPassword").getOrNull();
        }
    }
}
