0

I'm having project which converts proto files into scala case classes.

My build.sbt is -

ThisBuild / version := "0.1.0-SNAPSHOT"

lazy val root = (project in file("."))
  .settings(
    name := "proto-path-error"
  )
val openRtbCoreVersion = "1.5.5"
val googleCommonProtosVersion = "1.12.0"

val commonSettings: Seq[Def.Setting[_]] = Seq[Def.Setting[_]](
  scalaVersion := "2.12.14",
  organization := "com.td",
)

def scalaGrpcSettings: Seq[Def.Setting[_]] = Seq[Def.Setting[_]](
  libraryDependencies += "com.thesamet.scalapb"  %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
  libraryDependencies += "com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
  libraryDependencies += "com.google.api.grpc" % "proto-google-common-protos" % googleCommonProtosVersion % "protobuf",
  libraryDependencies += "com.google.openrtb"  % "openrtb-core" % openRtbCoreVersion,
  libraryDependencies += "com.google.openrtb"  % "openrtb-core"   % openRtbCoreVersion % "protobuf",

  PB.targets in Compile := Seq(
    PB.gens.java -> (sourceManaged in Compile).value,
    scalapb.gen(javaConversions = true) -> (sourceManaged in Compile).value
  ),

  PB.includePaths in Compile := Seq(
    target.value / "protobuf_external",
new File("definitions/common"),
),
  PB.protoSources in Compile := Seq(
    PB.externalIncludePath.value / "google" / "api",
    new File("definitions/common"),
    target.value / "protobuf_external"
  ),

  excludeFilter in PB.generate := new SimpleFileFilter(file => file.getCanonicalPath.contains("google/protobuf")),

  PB.additionalDependencies := Nil
)

project/plugins.sbt file is -

addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6")

libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.11"

project/build.properties is -

sbt.version = 1.3.13

The src/main/protobuf/definitions/common/common.proto -

syntax = "proto2";

option java_outer_classname = "CommonUtils";
package com.td.protobuf;

message CMap {
    map<int32, Assets> cs  = 1;
}

message Assets {
    repeated int32 assets = 1;
}

The whole project is on github here

When I compile the project it is not producting any case classes. I'm getting below output -

$ sbt clean compile
[info] welcome to sbt 1.3.13 (Azul Systems, Inc. Java 11.0.15)

[info] loading settings for project global-plugins from build.sbt ...

[info] loading global plugins from ~/.sbt/1.0/plugins

[info] loading settings for project proto-path-error-build from plugins.sbt ...

[info] loading project definition from ~/Documents/Coding/other/proto-path-error/project

[info] loading settings for project root from build.sbt ...

[info] set current project to proto-path-error (in build file:~/Documents/Coding/other/proto-path-error/)

[info] Executing in batch mode. For better performance use sbt's shell

[success] Total time: 0 s, completed Jul 5, 2022, 9:17:03 PM

[info] Protobufs files found, but PB.targets is empty. [success] Total time: 0 s, completed Jul 5, 2022, 9:17:04 PM

I've 2 issues

  1. PB.protoSources in Compile := new File("definitions/common") in build.sbt is not getting recognized.so I moved from proto-path-error/definitions to proto-path-error/src/main/protobuf/definitions.

  2. After moving the definitions it is recognized. But scala cases classes is not getting generated. I get log [info] Protobufs files found, but PB.targets is empty.

How can I fix these 2 issues?

user51
  • 8,843
  • 21
  • 79
  • 158
  • Hi, It looks like you define a method scalaGrpcSettings that returns some settings, but never apply these settings to any project. Also, protoSources is overridden such that src/main/protobuf is no longer picked up. You also seem to manually add scalapb-runtime and that shouldn't be necessary as it is added automatically. Can you start over and show a minimal example of the problem you are having? – thesamet Jul 06 '22 at 04:35
  • Have you looked at [Akka gPRC](https://doc.akka.io/docs/akka-grpc/current/index.html) and the [AkkaGrpcPlugin](https://doc.akka.io/docs/akka-grpc/current/client/walkthrough.html)? – Tim Jul 06 '22 at 17:31

0 Answers0