plugins {
    id 'java-library'
    id 'com.google.protobuf'
}

//用 Kotlin DSL 无法生成代码

dependencies {
    //grpc
    def grpcVersion = '1.49.2'
    api "io.grpc:grpc-okhttp:$grpcVersion"
    api "io.grpc:grpc-android:$grpcVersion"
    api "io.grpc:grpc-protobuf:$grpcVersion"
    api "io.grpc:grpc-stub:$grpcVersion"
    implementation 'org.apache.tomcat:annotations-api:6.0.53'
}

protobuf {
    generatedFilesBaseDir = "$projectDir/src"
    protoc {
        artifact = 'com.google.protobuf:protoc:3.21.7'
    }
    plugins {
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.49.2'
        }
    }
    generateProtoTasks {
        all().each { task ->
            task.builtins {
                java {
                    outputSubDir "java"
                }
            }
            task.plugins {
                grpc {
                    outputSubDir "java"
                }
            }
        }
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}