akka / akka-grpc

Akka gRPC
https://doc.akka.io/docs/akka-grpc/
Other
431 stars 123 forks source link

Integrate with Gradle protobuf plugin for Java projects #6

Closed ktoso closed 6 years ago

ktoso commented 6 years ago

As long as we have a plain protoc plugin we should be able to integrate with gradle nicely as well:

task.plugins {
  // Add grpc output without any option.  grpc must have been defined in the
  // protobuf.plugins block.
  // This yields
  // "--grpc_out=/path/to/output" on the protoc commandline.
  grpc { }
}

https://github.com/google/protobuf-gradle-plugin

Note that that's the official google gradle plugin

patriknw commented 6 years ago

Is ScalaPB a plain protoc plugin in the end, so that we can use it for generation of the data classes for scaladsl?

ktoso commented 6 years ago

Yes, we can use it like that. I think it also provides a binary, but we'll likely want to not use the binary but ship with the code and configure gradle / maven to call our runnables (as we want to set settings perhaps).

The snippet to run it is pretty much as simple as:

// this actually is code from protoc-sbt:

  override def run(req: Array[Byte]): Array[Byte] = {
    val registry = ExtensionRegistry.newInstance()
    Scalapb.registerAllExtensions(registry)
    val request = CodeGeneratorRequest.parseFrom(req, registry) // <<< raw protoc plugin proto types
    ProtobufGenerator.handleCodeGeneratorRequest(request).toByteArray
  }

where input is to be obtained from stdin and output is sent to stdout == this is a "normal protoc plugin" then.

patriknw commented 6 years ago

Thanks for clarifying, soo many tools

ktoso commented 6 years ago

This'll need a diagram, I'm sure ;-)

raboof commented 6 years ago

protobuf-gradle-plugin invokes protoc so we'd want to have a custom plugin that uses protoc-jar (like sbt-protoc does). Looks like building a gradle plugin from an sbt project is cumbersome, so perhaps this should be a separate project - but perhaps let's put it into the akka-grpc repo for convenience for now anyway.

ktoso commented 6 years ago

Hmmm... alternatively we could contribute this capability, it's been requested in the main plugin https://github.com/google/protobuf-gradle-plugin/issues/168 , my thought is that staying close to "what people use" may be beneficial..

Though if that's too hard (let's skim and see if it would be very hard, I can code groovy (did in the past...) if no one else wants to ;-)).

Otherwise the custom gradle plugin sounds good; Keeping it here in this repo sounds good too :)

raboof commented 6 years ago

We might not need to move to proto-jar, https://github.com/google/protobuf-gradle-plugin#pre-compiled-protoc-artifacts looks sufficient.

raboof commented 6 years ago

Constrained this issue to Java projects, split off Gradle support for Scala projects to #42

raboof commented 6 years ago

Status: all the pieces are in place so this works by plugging into the Google protobuf plugin (see plugin-tester-java), but it'd still be nice to have our own plugin for a readily-configured out-of-the-box experience