Skip to content

Support generating code from proto in src/test/protobufΒ #642

@lacarvalho91

Description

@lacarvalho91

We have proto files in src/test/protobuf which doesn't seem to be supported out of the box. To get it to work I've had to copy paste some settings from

override def projectSettings: Seq[Def.Setting[_]] =
.

inConfig(Test)(
  Seq(
    PB.targets := Fs2GrpcPlugin.autoImport.scalapbCodeGenerators.value,
    PB.protoSources := Seq(sourceDirectory.value / "protobuf"),
    fs2GrpcServiceSuffix := "Fs2Grpc",
    fs2GrpcOutputPath := sourceManaged.value / "fs2-grpc",
    scalapbCodeGeneratorOptions := Seq(CodeGeneratorOption.Grpc, CodeGeneratorOption.Fs2Grpc),
    scalapbCodeGenerators := {
      val options = scalapbCodeGeneratorOptions.value.toSet
      Target(
        scalapb.gen(
          flatPackage = options(CodeGeneratorOption.FlatPackage),
          javaConversions = options(CodeGeneratorOption.JavaConversions),
          grpc = options(CodeGeneratorOption.Grpc),
          singleLineToProtoString = options(CodeGeneratorOption.SingleLineToProtoString),
          asciiFormatToString = options(CodeGeneratorOption.AsciiFormatToString)
        ),
        sourceManaged.value / "scalapb"
      ) ::
        Option(
          Target(
            (
              SandboxedJvmGenerator.forModule(
                "scala-fs2-grpc",
                Artifact(
                  BuildInfo.organization,
                  s"${BuildInfo.codeGeneratorName}_${CrossVersion.binaryScalaVersion(BuildInfo.scalaVersion)}",
                  BuildInfo.version
                ),
                BuildInfo.codeGeneratorFullName + "$",
                Nil
              ),
              scalapbCodeGeneratorOptions.value.filterNot(_ == CodeGeneratorOption.Fs2Grpc).map(_.toString) :+
                s"serviceSuffix=${fs2GrpcServiceSuffix.value}"
            ),
            fs2GrpcOutputPath.value
          )
        ).filter(_ => scalapbCodeGeneratorOptions.value.contains(CodeGeneratorOption.Fs2Grpc)).toList
    }
  )
)

It would be good if we supported this out of the box like Akka gRPC does here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions