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

val redactionServiceVersion by rootProject.extra { "4.290.0" }
val pdftronRedactionServiceVersion by rootProject.extra { "4.90.0-RED10115.0" }
val redactionReportServiceVersion by rootProject.extra { "4.81.0" }
val searchServiceVersion by rootProject.extra { "2.90.0" }

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

group = "com.iqser.red.service"

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

pmd {
    isConsoleOutput = true
}

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"))
    }
}

java {
    withJavadocJar()
}

allprojects {

    tasks.withType<Javadoc> {
        options {
            this as StandardJavadocDocletOptions
            addBooleanOption("Xdoclint:none", true)
            addStringOption("Xmaxwarns", "1")
        }
    }
}
