为什么 sbt 在 build.sbt 工作时使用 Build.scala 报告“未找到:价值 PlayScala”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26134083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 06:36:28  来源:igfitidea点击:

Why does sbt report "not found: value PlayScala" with Build.scala while build.sbt works?

scalaplayframeworksbt

提问by Vikas Raturi

I am creating a multi-module sbt project, with following structure:

我正在创建一个多模块 sbt 项目,具有以下结构:

<root>
----build.sbt
----project
    ----Build.scala
    ----plugins.sbt
----common
----LoggingModule  

LoggingModuleis a Play Framework project, while commonis a simple Scala project.

LoggingModule是一个 Play Framework 项目,而common是一个简单的 Scala 项目。

In plugins.sbt:

plugins.sbt

resolvers += "Typesafe repo" at "http://repo.typesafe.com/typesafe/releases/"

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.3")  

While I have this in build.sbt, all works fine and it recognises PlayScala:

虽然我有这个build.sbt,但一切正常,它可以识别PlayScala

name := "Multi-Build"

lazy val root = project.in(file(".")).aggregate(common, LoggingModule).dependsOn(common, LoggingModule)

lazy val common = project in file("common")

lazy val LoggingModule = (project in file("LoggingModule")).enablePlugins(PlayScala)  

However as soon I put this in project/Build.scalainstead of `build.sbt' as follows:

但是,一旦我将其放入project/Build.scala而不是`build.sbt',如下所示:

object RootBuild extends Build {  

  lazy val root = project.in(file("."))
    .aggregate(common, LoggingModule)
    .dependsOn(common, LoggingModule)

  lazy val common = project in file("common")
  lazy val LoggingModule = (project in file("LoggingModule")).enablePlugins(PlayScala)

  ...//other settings
}

it generates error as:

它生成错误为:

not found: value PlayScala
lazy val LoggingModule = (project in file("LoggingModule")).enablePlugins(PlayScala)
                                                                          ^

How to solve the issue?

如何解决问题?

回答by sjrd

It's just a missing import.

这只是一个缺少的导入。

In .sbtfiles, some things are automatically imported by default: contents of objects extending Plugin, and (>= 0.13.5) autoImportfields in AutoPlugins. This is the case of PlayScala.

.sbt文件中,默认情况下会自动导入一些内容:对象扩展的内容Plugin,以及s 中的(>= 0.13.5)autoImport字段AutoPlugin。这是 的情况PlayScala

In a Build.scalafile, normal Scala import rules apply. So you have to import things a bit more explicitly. In this case, you need to import play.PlayScala(or use .enabledPlugins(play.PlayScala)directly).

Build.scala文件中,适用正常的 Scala 导入规则。所以你必须更明确地导入东西。在这种情况下,您需要import play.PlayScala(或.enabledPlugins(play.PlayScala)直接使用)。