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

group = "cc-lotus.gaf3"
version = rootProject.version

plugins {
    id("java")
    id("maven-publish")
    id("io.spring.dependency-management")
    id("org.springframework.boot")
    kotlin("jvm")
    kotlin("plugin.spring")
    kotlin("plugin.jpa")
}

dependencies {
    implementation(project(path = ":shared:cloud"))
    implementation(project(path = ":shared:util"))
    implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.springframework.boot:spring-boot-configuration-processor")
    implementation("org.springframework.cloud:spring-cloud-starter-gateway")
    implementation("org.springframework.cloud:spring-cloud-gateway-webflux")
    implementation("org.springframework.boot:spring-boot-starter-data-redis")
    implementation("io.jsonwebtoken:jjwt-api")
    implementation("io.jsonwebtoken:jjwt-impl")
    implementation("io.jsonwebtoken:jjwt-jackson")
    implementation("com.alibaba:fastjson")
    implementation("commons-io:commons-io")
    implementation(kotlin("reflect"))
    implementation(kotlin("stdlib-jdk8"))
    implementation(project(path = ":services:service-verify", configuration = "lib"))
    implementation(project(path = ":services:service-token", configuration = "lib"))
}

dependencyManagement {
    imports {
        mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
    }
}

tasks.named<BootJar>(name = "bootJar") {
    archiveBaseName.set("gaf3-${project.name}")
}

tasks.register<Jar>(name = "libJar") {
    archiveBaseName.set("gaf3-${project.name}-lib")
    from(project.the<SourceSetContainer>()["main"].output)
    include("gaf3/**")
    exclude("gaf3/core/gateway/bean/**")
    exclude {
        it.name.endsWith("Application.class")
    }
    exclude {
        it.name.endsWith("ApplicationKt.class")
    }
    exclude {
        it.name.endsWith("Application${'$'}Companion.class")
    }
}
tasks.build { dependsOn(tasks.named("libJar")) }

configurations {
    create("lib")
}

artifacts {
    add("lib", tasks["libJar"])
}

tasks {
    processResources {
        filesMatching("application-services.yml") {
            // expand("db.user" to dbUser)
            expand(project.properties)
        }
    }
}
publishing {
    publications {
        create<MavenPublication>("maven") {
            artifact(tasks["libJar"])
            artifactId = "gaf-core-${project.name}"
            // from(components["java"])
        }
    }
}



