我很难理解scalapb的语法,特别是我试图为多项目SBT构建添加多个.proto源目录。
我的项目结构如下:
/build.sbt
/main/src/protobuf
/common/main/src/protobuf
/client/main/src/protobuf
我的build.sbt如下:
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)
当我运行sbt compile
时,收到以下错误消息:
[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 ?
有人可以指出我正确的方向吗?我在这里没有理解一些基本概念......
修改
好的,所以我指的是protoDirectories的错误序列。我修改了build.sbt以反映新的更改。我仍然有一个问题,我的.proto文件没有在子项目中编译。如果我将.proto文件移动到root / main / src / protobuf,它们就可以正常编译。
答案 0 :(得分:2)
如果两个项目都包含src/main/protobuf
中的文件,则需要分别为这两个项目启用ScalaPB插件。此示例还说明了如何设置导入搜索路径。完整示例位于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)