首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在sbt多项目中定义编译设置?

如何在sbt多项目中定义编译设置?
EN

Stack Overflow用户
提问于 2021-02-07 23:26:38
回答 1查看 130关注 0票数 0

我正在尝试使用sbt multi-project配置一个新的Scala版本。我想使用sbt-protoc,尤其是ScalaPB,它需要以下配置设置:

代码语言:javascript
复制
Compile / PB.targets := Seq(
  scalapb.gen() -> (Compile / sourceManaged).value
)

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

我当前的build.sbt

代码语言:javascript
复制
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
  )

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

代码语言:javascript
复制
[info] Protobufs files found, but PB.targets is empty.
EN

回答 1

Stack Overflow用户

发布于 2021-02-08 20:59:05

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

代码语言:javascript
复制
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
  )
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66089595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档