Has anyone used Kotlin DSL with Google's Protobuf?...
# gradle
x
Has anyone used Kotlin DSL with Google's Protobuf? I'm unable to "translate" the
protobuf
plug-in from Gradle. This is what I got so far:
Copy code
configure<ProtobufConfigurator> { //protobuf
  generatedFilesBaseDir = "$projectDir/build/generated"

  //generateProtoTasks {
  //  all() * . plugins {
  //    grpc { option "enable_deprecated = false" }
  //  }
  //}
  generateProtoTasks({ ??? })

  //plugins {
  //  grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpc_version}" }
  //}

  //  protoc {
  //    artifact = "com.google.protobuf:protoc:3.3.0"
  //  }
}
Maybe it’s not a full example for your case, but could give you some clues how to port it
Also, please check my next messages after this example, there are highlighting problem in kotlin-dsl + Idea. Also, maybe you could create task for protobuf team to fix compatability with kotlin-dsl
x
Thanks, @gildor! That will nail it! I think I don't understand, at all, the closures thing...thanks again!
g
“closure things” there are because protobuf plugin provides only API based on Groovy’s Closure class + dynamic properties. To work better with Kotlin plugin should provide
Action<T>
based API. kotlin-dsl provides few helper functions like delegateClosureOf to work with Groovy
Closure
class and
setProperty
and
invokeMethod
to work with dynamic properties and methods of closure
x
Another pretty annoying issue I'm facing is that whenever I run
./gradlew clean build
I'm getting a lot of `Unresolve reference: blah blah`; I think it's because
compileKotlin
runs before
generateProto
and it can't find the "generated" classes/stubs from gRPC. Are you facing the same?
If I migrate the project to Java everything works flawlessly...it does execute the required tasks in a determined order that makes sense
g
I also have this:
Copy code
java.sourceSets["main"].java {
    val gen = protobuf.protobuf.generatedFilesBaseDir
    srcDirs += files("$gen/main/java", "$gen/main/grpc")
}
I remember that I had some problem with generateProto task order, but not now, maybe because I separated proto generation to a separate module. You can add dependency to generateProto manually, to run before compileKotlin
x
Yeah, I get it, but it would be nice if it works like in a Java project out-of-the-box...I'm trying not to put anything "custom"
g
I think it’s a problem of protobuf gradle plugin
x
Maybe...but I only get the issues when I "switch" the project into a Kotlin-powered one ― I've tried with Gradle and Kotlin DSL. So I'm guessing it should be something related with Kotlin and the way Gradle works with it.
g
I think that they just depends on javaCompileTask.
they don’t use annotation processing phase, just run external tool before javaCompileTask
189 Views