plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.5'
    id 'io.spring.dependency-management' version '1.1.0'
    id 'org.sonarqube' version '4.0.0.2929'
}

group = 'com.caliverse.admin'
version = '1.0.0'

/*ava 17 버전과 호환*/
java {
    sourceCompatibility = '17'
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.2'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-aop'

    implementation 'org.apache.httpcomponents.client5:httpclient5:5.4.1'
    implementation 'org.apache.httpcomponents.core5:httpcore5:5.3.1'

    //Json
    implementation group: 'org.json', name: 'json', version: '20231013'
    implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'

    //aws
    implementation platform('software.amazon.awssdk:bom:2.20.155')
    implementation 'software.amazon.awssdk:dynamodb'
    implementation 'software.amazon.awssdk:dynamodb-enhanced'
    implementation 'software.amazon.awssdk:s3:2.21.5'
    implementation 'software.amazon.awssdk:auth'
    implementation 'software.amazon.awssdk:cloudwatch'

    //메일 서버
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    //mongoDB
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

    //POI
    implementation 'org.apache.poi:poi:5.2.2'
    implementation 'org.apache.poi:poi-ooxml:5.2.2'

    //spring batch
    implementation 'org.springframework.boot:spring-boot-starter-batch'

    // jwt
    implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
    implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
    implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
    //swagger
    implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.1.0'

    // RabbitMQ
    implementation 'com.rabbitmq:amqp-client:5.21.0'

    // proto
    implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.21.12'
    implementation group: 'com.google.protobuf', name: 'protobuf-java-util', version: '3.25.3'

    //redis
    implementation 'redis.clients:jedis:4.3.1'
    implementation 'org.springframework.boot:spring-boot-starter-data-redis'

    compileOnly 'org.projectlombok:lombok'
    runtimeOnly 'com.mysql:mysql-connector-j'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
 
}

sonarqube {
    properties {
        property "sonar.projectKey", "admintool"
        property "sonar.host.url", "http://localhost:9000"
        property "sonar.token", "sqp_097d54f557bc6f85200f6340bbf86906a00ac38c"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.exclusions", "**/build/**, **/src/main/java/com/caliverse/admin/domain/RabbitMq/**, **/logs/**, **/.gradle/**, **/bin/**, **/.idea/**"
    }
}


tasks.named('test') {
    useJUnitPlatform()
}
tasks.named('jar'){
    enabled=false
}
tasks {
    processResources {
        duplicatesStrategy = org.gradle.api.file.DuplicatesStrategy.INCLUDE
    }
}

def getDate() {
    new Date().format('yyyyMMdd')
}

// 빌드 종류별 처리
def profiles = project.hasProperty('profile') ? project.property('profile') : 'local'
println "Active profile: $profiles"

tasks.withType(JavaExec) {
    systemProperty 'spring.profiles.active', profiles
}

bootJar{

    archivesBaseName = 'CaliverseAdminAPI'
    archiveVersion = '1.0.0'

//    archiveFileName = "CaliverseAdminAPI-${version}-${profile}.jar"
    archiveFileName = "CaliverseAdminAPI-${profiles}.jar"
}
sourceSets {
    /**
     * 개발환경 : local
     * 운영환경 : live
     * 환경 변경하여 빌드시 ext.profile 값 변경
     */
//    def Properties properties = new Properties()
//    Reader reader = new FileReader(project.rootProject.file('src/main/resources/config/application.yml'))
//    properties.load(reader)
//    ext.profile = properties.getProperty('active')
    println "Active resources set src/main/resources/config/${profiles}"
    main {
        java {
            srcDirs "src/main/java"
        }
        resources {
            srcDirs "src/main/resources/config","src/main/resources/config/${profiles}"
        }
    }
}
