apply plugin: "com.google.protobuf"
apply plugin: "kotlin"

buildscript {
  dependencies {
    classpath libraries['com.google.protobuf:protobuf-gradle-plugin']
  }
}

protobuf {
  protoc {
    artifact = libraries['com.google.protobuf:protoc']
  }
  plugins {
    grpc {
      artifact = libraries['io.grpc:protoc-gen-grpc-java']
    }
    grpckt {
      artifact = libraries['io.grpc:protoc-gen-grpc-kotlin']
    }
  }
  generateProtoTasks {
    all()*.plugins {
      grpc {}
      grpckt {}
    }
  }
}

sourceSets {
  main {
    java {
      srcDir file("${protobuf.generatedFilesBaseDir}/main/grpc")
      srcDir file("${protobuf.generatedFilesBaseDir}/main/java")
    }
    kotlin {
      srcDir file("${protobuf.generatedFilesBaseDir}/main/grpckt")
    }
  }
}

dependencies {
  api libraries['com.google.protobuf:protobuf-java']
  api libraries['io.grpc:grpc-core']
  api libraries['io.grpc:grpc-protobuf']
  api libraries['io.grpc:grpc-stub']
  api libraries['io.grpc:grpc-kotlin-stub']
  api libraries['javax.annotation:javax.annotation-api']

  api libraries['org.jetbrains.kotlin:kotlin-stdlib']
  api libraries['org.jetbrains.kotlinx:kotlinx-coroutines-core']
}
