/*
 * Copyright 2021 DataCanvas
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

plugins {
    id 'application'
    id 'org.springframework.boot' version '2.5.15'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id "com.google.protobuf" version "0.8.18"
    id "com.gorylenko.gradle-git-properties" version "${gradleGitCommitVersion}"
}

application {
    getMainClass().set('io.dingodb.proxy.DingoApplication')
}

dependencies {
    annotationProcessor group: 'com.google.auto.service', name: 'auto-service', version: 'auto-service'.v()
    compileOnly group: 'com.google.auto.service', name: 'auto-service', version: 'auto-service'.v()

    implementation group: 'org.slf4j', name: 'slf4j-api', version: 'slf4j'.v()
    implementation group: 'ch.qos.logback', name: 'logback-classic', version: 'logback'.v()
    implementation group: 'ch.qos.logback', name: 'logback-core', version: 'logback'.v()

    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-aop'

    implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
    implementation group: 'org.mapstruct', name: 'mapstruct', version: 'mapstruct'.v()

    implementation group: 'io.dingodb.expr', name: 'dingo-expr-parser', version: 'dingo-expr'.v()
    implementation group: 'io.dingodb.expr', name: 'dingo-expr-rel', version: 'dingo-expr'.v()
    implementation group: 'io.dingodb.expr', name: 'dingo-expr-common', version: 'dingo-expr'.v()
    implementation group: 'io.dingodb.expr', name: 'dingo-expr-coding', version: 'dingo-expr'.v()

    implementation project(":dingo-net-api")
    implementation project(":dingo-net-netty")
    implementation project(":dingo-common")
    implementation project(":dingo-meta-api")
    implementation project(":dingo-verify")
    implementation project(":dingo-client")

    implementation group:'com.google.protobuf', name:'protobuf-java', version: 'protobuf'.v()

    implementation group: 'io.grpc', name: 'grpc-protobuf', version: 'grpc'.v()
    implementation group: 'io.grpc', name: 'grpc-protobuf-lite', version: 'grpc'.v()
    implementation group: 'io.grpc', name: 'grpc-stub', version: 'grpc'.v()
    implementation group: 'io.grpc', name: 'grpc-netty-shaded', version: 'grpc'.v()

    implementation group: 'io.dingodb', name: 'dingo-sdk', version: project.version
    implementation group: 'org.yaml', name: 'snakeyaml', version: 'snakeyaml'.v()

    compileOnly group: 'org.projectlombok', name: 'lombok', version: 'lombok'.v()
    compileOnly group: 'org.mapstruct', name: 'mapstruct-processor', version: 'mapstruct'.v()
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: 'lombok'.v()
    annotationProcessor group: 'org.mapstruct', name: 'mapstruct-processor', version: 'mapstruct'.v()
}

bootJar.dependsOn([
    ':dingo-client:fatJar',
    ':dingo-net-api:jar',
    ':dingo-net-netty:jar',
    ':dingo-common:jar',
    ':dingo-meta-api:jar',
    ':dingo-verify:jar',
    ':dingo-client:jar'
])

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.25.5'
    }
    generatedFilesBaseDir = "$projectDir/build/generated/sources/protobuf/"
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.69.0'
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    option 'lite'
                }
            }
            task.plugins {
                grpc {
                    option 'lite'
                }
            }
        }
    }
}
sourceSets {
    main {
        proto {
            srcDir 'src/main/dingo-proto/proto/'
        }
        java {
            srcDirs 'build/generated/sources/protobuf/'
        }
    }
}

test {
    useJUnitPlatform()
}
