Scala 构建脚本 - 构建单元中没有定义项目
Scala build script - no projects defined in build unit
我刚刚尝试使用基于 Scala 的自定义构建脚本设置 SBT 项目,但收到以下错误消息:
[error] No projects defined in build unit /home/user/scala/myProject
myProject 目录如下所示:
├── project
│ ├── myProjectBuild.scala
│ └── target
├── src
│ └── main
└── target
├── resolution-cache
├── scala-2.9.2
└── streams
这里是myProjectBuild.scala的内容:
import sbt._
import sbt.Keys._
object myProjectBuild extends Build {
val myProjectDependencies = List(
"org.scalatest" % "scalatest_2.11" % "2.2.1" % "test"
)
val myProjectSettings = List(
name := "myProject",
version := "1.0",
scalaVersion := "2.11.5",
libraryDependencies := myProjectDependencies
)
override lazy val settings = super.settings ++ myProjectSettings
}
有什么想法吗?
我找到了解决问题的方法。我将以下行添加到 scala 构建文件中:
lazy val root = Project(id = "HardyHeron",
base = file("."),
settings = Project.defaultSettings ++ hardyHeronSettings)
在那之后它几乎成功了但是我得到了一个 MissingRequirementError 因为行
libraryDependencies := myProjectDependencies
改成后
libraryDependencies ++= myProjectDependencies
如here所述,编译正确。我不确定为什么它现在起作用了。我所指的书(Learning Scala)提供了一个没有定义 rool val 的 scala 构建文件。那么它应该 运行 没有这条线吗?
有区别Bare Build Definition, Multi-Project .sbt definition and Scala Build Definition。关于第一个:
Unlike Multi-project .sbt build definition and .scala build definition
that explicitly define a Project definition, bare build definition
implicitly defines one based on the location of the .sbt file.
Instead of defining Projects, bare .sbt build definition consists of a
list of Setting[_] expressions.
The current recommendation is to use Multi-project .sbt build definition.
因此,它允许您不显式指定任何项目,但它已经过时,不推荐使用。
P.S。我想您正在阅读 "Learning Scala"(而不是 this)的一些过时修订版,或者作者使用了基于 .sbt
-build 的示例。
我刚刚尝试使用基于 Scala 的自定义构建脚本设置 SBT 项目,但收到以下错误消息:
[error] No projects defined in build unit /home/user/scala/myProject
myProject 目录如下所示:
├── project
│ ├── myProjectBuild.scala
│ └── target
├── src
│ └── main
└── target
├── resolution-cache
├── scala-2.9.2
└── streams
这里是myProjectBuild.scala的内容:
import sbt._
import sbt.Keys._
object myProjectBuild extends Build {
val myProjectDependencies = List(
"org.scalatest" % "scalatest_2.11" % "2.2.1" % "test"
)
val myProjectSettings = List(
name := "myProject",
version := "1.0",
scalaVersion := "2.11.5",
libraryDependencies := myProjectDependencies
)
override lazy val settings = super.settings ++ myProjectSettings
}
有什么想法吗?
我找到了解决问题的方法。我将以下行添加到 scala 构建文件中:
lazy val root = Project(id = "HardyHeron",
base = file("."),
settings = Project.defaultSettings ++ hardyHeronSettings)
在那之后它几乎成功了但是我得到了一个 MissingRequirementError 因为行
libraryDependencies := myProjectDependencies
改成后
libraryDependencies ++= myProjectDependencies
如here所述,编译正确。我不确定为什么它现在起作用了。我所指的书(Learning Scala)提供了一个没有定义 rool val 的 scala 构建文件。那么它应该 运行 没有这条线吗?
有区别Bare Build Definition, Multi-Project .sbt definition and Scala Build Definition。关于第一个:
Unlike Multi-project .sbt build definition and .scala build definition that explicitly define a Project definition, bare build definition implicitly defines one based on the location of the .sbt file.
Instead of defining Projects, bare .sbt build definition consists of a list of Setting[_] expressions.
The current recommendation is to use Multi-project .sbt build definition.
因此,它允许您不显式指定任何项目,但它已经过时,不推荐使用。
P.S。我想您正在阅读 "Learning Scala"(而不是 this)的一些过时修订版,或者作者使用了基于 .sbt
-build 的示例。