plugins {
    id 'org.springframework.boot' version '3.4.0' apply false
    //id 'io.spring.dependency-management' version '1.1.6' apply false
    id 'java'
}

allprojects {
    group = 'com.unicorn'
    version = '1.0.0'
    sourceCompatibility = '21'
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    
    repositories {
        mavenCentral()
    }

    dependencies {
        // Spring Boot Starters
        implementation 'org.springframework.boot:spring-boot-starter'
        implementation 'org.springframework.boot:spring-boot-starter-validation'
        implementation 'org.springframework.boot:spring-boot-starter-aop' // AOP: 로깅 처리 자동화를 위해 사용

        // Utils
        implementation 'com.google.code.gson:gson'

        // Lombok
        compileOnly 'org.projectlombok:lombok'
        annotationProcessor 'org.projectlombok:lombok'

        // Test Dependencies
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
        testImplementation 'org.junit.jupiter:junit-jupiter-api'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
        testImplementation 'org.mockito:mockito-core'
        testImplementation 'org.mockito:mockito-junit-jupiter'

        // Lombok for Tests
        testCompileOnly 'org.projectlombok:lombok'
        testAnnotationProcessor 'org.projectlombok:lombok'
    }

    // Test Configuration
    sourceSets {
        test {
            java {
                srcDirs = ['src/test/java']
            }
        }
    }

    test {
        useJUnitPlatform()
        include '**/*Test.class'
        testLogging {
            events "passed", "skipped", "failed"
        }
    }
}

//-- Biz와 common 모듈이 아닌 경우 인프라 관련 라이브러리 추가
configure(subprojects.findAll { !it.name.endsWith('-biz') && it.name != 'common' }) {
    dependencies {
        // Spring Boot
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.springframework.boot:spring-boot-starter-validation'
        // data
        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
        // JWT
        implementation 'org.springframework.boot:spring-boot-starter-security'
        implementation 'com.auth0:java-jwt:4.4.0'           //JWT unitlity
        implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
        runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
        runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'

        // Swagger
        implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0'

        //-- spring security test
        testImplementation 'org.springframework.security:spring-security-test'

        // Test Containers
        testImplementation 'org.testcontainers:postgresql'
        testImplementation 'org.testcontainers:junit-jupiter'

        // WebFlux for WebMvc Testing
        implementation 'org.springframework.boot:spring-boot-starter-webflux'
    }
}

//-- Biz와 common 모듈은 일반Jar만 생성하고 실행Jar는 생성되지 않게 함
configure(subprojects.findAll { it.name.endsWith('-biz') || it.name == 'common' }) {
    bootJar.enabled = false
    jar.enabled = true
}
