3

I'm having some difficulties understanding the syntax for scalapb, specifically I'm trying to add multiple .proto source directories for a multi-project SBT build.

My project structure is as follows:

/build.sbt
/main/src/protobuf
/common/main/src/protobuf
/client/main/src/protobuf

My build.sbt is as follows:

name := "myApp"

import Dependencies._

import com.trueaccord.scalapb.{ScalaPbPlugin => PB}

val protoDirectories = Seq(
  file("common/src/main/protobuf"),
  file("client/src/main/protobuf")
)

sourceDirectories in PB.protobufConfig ++= protoDirectories

PB.protobufSettings ++ Seq(
  flatPackage := false
)

lazy val common = (project in file("common")).
  settings(Commons.settings: _*).
  settings(libraryDependencies ++= commonDependencies)

lazy val client = (project in file("client")).
  settings(Commons.settings: _*).
  settings(libraryDependencies ++= clientDependencies).
  dependsOn(common)

When I run sbt compile, I get the following error message:

[error] Reference to undefined setting: 
[error] 
[error]   sphere/*:sourceDirectories from myApp/*:sourceDirectories (<path_to_project_dir>\build.sbt:11)
[error]      Did you mean myApp/protobuf:sourceDirectories ?

Could someone please point me in the right direction? I'm failing to understand some basic concept here...

EDIT

Ok, so I was pointing to the wrong sequence for the protoDirectories. I have amended the build.sbt to reflect the new changes. I still have a problem that my .proto files are not compiled in the sub projects. If I move my .proto files to the root /main/src/protobuf, they compile just fine.

dthagard
  • 823
  • 7
  • 23

1 Answers1

2

You need to enable the ScalaPB plugin for both projects separately if both contain files in src/main/protobuf. This example also shows how to set the import search path. A full example is at https://github.com/thesamet/scalapb-test/tree/multiproject

import com.trueaccord.scalapb.{ScalaPbPlugin => PB}

version in PB.protobufConfig := "3.0.0-beta-2"

lazy val common = (project in file("common")).
  settings(PB.protobufSettings)

lazy val client = (project in file("client")).
  settings(PB.protobufSettings ++ Seq(
    // If you want proto files in client to import proto files in common.
    PB.includePaths in PB.protobufConfig += file("common/src/main/protobuf")
  )).
  dependsOn(common)
thesamet
  • 6,382
  • 2
  • 31
  • 42