import org.springframework.boot.gradle.tasks.bundling.BootBuildImage

plugins {
    application
    id("com.iqser.red.service.java-conventions")
    id("org.springframework.boot") version "3.1.5"
    id("io.spring.dependency-management") version "1.1.6"
    id("org.sonarqube") version "4.4.1.3373"
    id("io.freefair.lombok") version "8.6"
}

configurations {
    all {
        exclude(group = "commons-logging", module = "commons-logging")
        exclude(group = "org.springframework.boot", module = "spring-boot-starter-log4j2")
        exclude(group = "com.iqser.red.commons", module = "logging-commons")
    }
}

dependencies {
    api(project(":persistence-service-processor-v1"))
    api(project(":persistence-service-external-api-impl-v1"))
    api(project(":persistence-service-external-api-impl-v2"))
    api(project(":persistence-service-internal-api-impl-v1"))
    api(project(":persistence-service-shared-mongo-v1"))
    api("com.iqser.red.commons:storage-commons:2.50.0")
    api("junit:junit:4.13.2")
    api("org.apache.logging.log4j:log4j-slf4j-impl:2.20.0")
    api("net.logstash.logback:logstash-logback-encoder:7.4")
    implementation("ch.qos.logback:logback-classic")
    implementation("org.liquibase:liquibase-core:4.29.2") // Needed to be set explicit, otherwise spring dependency management sets it to 4.20.0

    testImplementation("org.springframework.amqp:spring-rabbit-test:3.0.2")
    testImplementation("org.springframework.security:spring-security-test:6.0.2")
    testImplementation("org.testcontainers:postgresql:1.17.1")
    testImplementation("org.springframework.boot:spring-boot-starter-test:3.0.4")
    testImplementation("com.yannbriancon:spring-hibernate-query-utils:2.0.0")
    testImplementation("com.google.protobuf:protobuf-java:4.27.1")
}

description = "persistence-service-server-v1"

tasks.named<BootBuildImage>("bootBuildImage") {

    builder.set("docker-proxy.knecon.com/paketobuildpacks/builder:base")
    runImage.set("docker-proxy.knecon.com/paketobuildpacks/run:base-cnb")

    environment.put("BPE_DELIM_JAVA_TOOL_OPTIONS", " ")
    environment.put("BPE_APPEND_JAVA_TOOL_OPTIONS", "-Dfile.encoding=UTF-8")
    environment.put("BPE_DEFAULT_LANG", "en_US.utf8") // FileInputStream or ZipInputStream does not seem to care for file.encoding

    imageName.set("nexus.knecon.com:5001/red/${project.name}:${project.version}")
    if (project.hasProperty("buildbootDockerHostNetwork")) {
        network.set("host")
    }

    docker {
        if (project.hasProperty("buildbootDockerHostNetwork")) {
            bindHostToBuilder.set(true)
        }
        verboseLogging.set(true)

        builderRegistry {
            username.set(providers.gradleProperty("mavenUser").getOrNull())
            password.set(providers.gradleProperty("mavenPassword").getOrNull())
            email.set(providers.gradleProperty("mavenEmail").getOrNull())
            url.set("https://docker-proxy.knecon.com:5001/")
        }

        publishRegistry {
            username.set(providers.gradleProperty("mavenUser").getOrNull())
            password.set(providers.gradleProperty("mavenPassword").getOrNull())
            email.set(providers.gradleProperty("mavenEmail").getOrNull())
            url.set("https://nexus.knecon.com:5001/")
        }
    }
}
