plugins {
    id 'java'
    id 'checkstyle'
}
// Get version from main project gradle
def packVersion = properties.get("packageVersion");
def jarVersion = properties.get("jarVersion");
//println "packageVersion is ${projVersion}"


java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

repositories {
    mavenCentral()
    flatDir { dirs "lib" }
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
    jaxb
}

dependencies {
    implementation libs.bouncycastle
    implementation libs.lombok
    implementation libs.jackson.core
    implementation libs.jackson.databind
    implementation libs.jakarta.api
    implementation libs.jakarta.xml
    implementation libs.guava
    implementation libs.commons.codec
    implementation libs.commons.lang3
    implementation libs.commons.io
    implementation libs.minimal.json

    implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
    implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
    implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.1'

    testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
    testImplementation 'org.junit.platform:junit-platform-launcher:1.9.3'
    testImplementation 'org.hamcrest:hamcrest:2.2'
    testImplementation project(path: ':HIRS_AttestationCA')

    testImplementation 'org.mockito:mockito-core:4.2.0'

    compileOnly libs.lombok
    annotationProcessor libs.lombok

}

checkstyle {
    toolVersion = '10.12.7'
    configFile file("${rootDir}/config/checkstyle/checkstyle.xml")
}
// https://github.com/checkstyle/checkstyle/issues/14211#issuecomment-1884129948
configurations.checkstyle {
    resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") {
        select("com.google.guava:guava:0")
    }
}
checkstyleMain {
    source ='src/main/java'
}
checkstyleTest {
    source ='src/test/java'
}
tasks.withType(Checkstyle) {
    reports {
        xml.required = false
        html.required = true
    }
}

test {
    useJUnitPlatform()
}

jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    manifest {
        attributes(
                'Class-Path': configurations.runtimeClasspath.files.collect { it.getName() }.join(' ')
        )
    }
    //jar name format: [archiveBaseName]-[archiveAppendix]-[archiveVersion]-[archiveClassifier].[archiveExtension]
    archiveVersion = jarVersion
}

//task generateXjcLibrary(type:Exec) {
//    workingDir 'config'
//
//    commandLine './genXjcLibrary.sh'
//}
//compileJava.dependsOn generateXjcLibrary