0

我正在尝试使用sbt multi-project配置新的 Scala 构建。我想使用sbt- protoc,特别是需要此配置设置的 ScalaPB:

Compile / PB.targets := Seq(
  scalapb.gen() -> (Compile / sourceManaged).value
)

现在的问题是如何sbt.librarymanagement.Configurations.Compile在多项目中正确应用该配置。我正在使用 Scala 2.13 和 sbt 1.4.7。

我的当前build.sbt

Compile / PB.targets := Seq(
  scalapb.gen() -> (Compile / sourceManaged).value
)

lazy val commonSettings = List(
  scalaVersion := scala212,
  scalacOptions ++= Seq(
    "utf8",
    "-Ypartial-unification"
  )
)

lazy val core = (project in file("core"))
  .settings(
    commonSettings,
    name := "twirp4s-core",
    crossScalaVersions := Seq(scala212, scala213),
    libraryDependencies ++= Seq(
      catsCore,
      circeCore,
      circeGeneric,
      circeParser,
      http4sDsl,
      http4sCirce
    ),
    addCompilerPlugin(betterMonadicForPlugin),
  )

lazy val root = (project in file("."))
  .aggregate(core)
  .settings(
    name := "twirp4s-root",
    libraryDependencies += scalaTest % Test,
    skip in publish := true
  )

当我尝试编译我的项目时,编译器会说:

[info] Protobufs files found, but PB.targets is empty.
4

1 回答 1

2

正如您已经知道的那样,@Seth 在评论中建议,Compile / PB.targets 进入 core.settings 是可行的。这是build.sbt你应该使用的:

lazy val commonSettings = List(
  scalaVersion := scala212,
  scalacOptions ++= Seq(
    "utf8",
    "-Ypartial-unification"
  )
)

lazy val core = (project in file("core"))
  .settings(
    commonSettings,
    name := "twirp4s-core",
    crossScalaVersions := Seq(scala212, scala213),
    libraryDependencies ++= Seq(
      catsCore,
      circeCore,
      circeGeneric,
      circeParser,
      http4sDsl,
      http4sCirce
    ),
    addCompilerPlugin(betterMonadicForPlugin),
    Compile / PB.targets := Seq(
      scalapb.gen() -> (Compile / sourceManaged).value
    )
  )

lazy val root = (project in file("."))
  .aggregate(core)
  .settings(
    name := "twirp4s-root",
    libraryDependencies += scalaTest % Test,
    skip in publish := true
  )
于 2021-02-08T12:59:04.660 回答